java JQuery ajax GET请求,响应状态为200 OK时未触发成功
发送REST调用时,我收到一个奇怪的JSON响应数据响应。我可以在firebug中看到响应状态是正常的,但身体是空的,尽管尝试使用海报效果很好。这是我的JQuery调用:
var urlPath = "http://localhost:8080/coreserver/rest";
function totalAccountCount()
{
$.ajax({
type: "GET",
url: urlPath + "/summary/totalAccountCount",
dataType: "json",
success: function (resp) {
var rowText = "<tr><td>Total Accounts</td><td>" + resp.wrapper.item + "</td></tr>";
$(rowText).appendTo(tbody);
//loadCustomers(resp);
alert("STATUS: " + xhr.status + " " + xhr.statusText);
},
error: function(xhr, textStatus, errorThrown){
alert("Error: fails");
//$("#message").html(resp.e + " - STATUS: " + xhr.status + " " + xhr.statusText);
}
});
}
调试时,它不会转到成功分支,而是转到错误分支。这是我的资源:
@GET
@Path("/totalAccountCount")
@Produces({MediaType.APPLICATION_JSON})
public JaxbWrapper<Integer> getTotalAccountCount() {
return new JaxbWrapper<Integer>((int)this.accountStore.count());
}
我已经知道用JaxbWrapper
阅读我的回复可能是错误的,但根本不会成功,所以现在我想确保这是可行的
我希望能得到一些帮助。提前谢谢
# 1 楼答案
async:false解决了这个问题。它总是跳转到错误函数,然后成功
更新1
让它工作的真正原因是我在我的网站上添加了以下内容。服务器端的xml:
有人能理解这一点吗
更新2
只是缓存了一下。问题解决了
谢谢