我的Jquery代码如下,但它总是给'加载失败的内容',我需要做一个Ajax调用来获取数据使用rest api。我正在使用jQuery 1.3.2。AJAX调用:“无法加载内容”
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() {
var cat_id = ${coreNode.ancestors[0].id};
var restUrl = "http://xyz./restapi/vc/categories/id/"+cat_id+"/boards";
$.ajax({
type: "POST",
url: restUrl,
contentType: "text/xml; charset=utf-8",
data: "DATA",
success: function (response) {
alert(restUrl);
});
},
error: function (response) {
$('#float-threads').html('Failed to load the content');
}
});
});
</script>
<div id="float-threads">
</div>
什么错误? url是否可以返回404? – Sumurai8
错误出现在url:'restUrl'中,请删除该报价。和数据:“数据”,你需要将数据作为变量传递给它并赋值。 –
另外,如果你的目的是简单地从服务器获取数据,你应该使用GET而不是POST;) – Terry