我在发送 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
读取我的响应可能是错误的,但根本没有成功,所以现在我想确保它有效。
我希望得到一些帮助。提前致谢。
最佳答案
async: false 解决了它。它一直跳到错误函数然后成功
更新1
让它工作的真正原因是因为我在服务器端的 web.xml 中添加了以下内容:
<init-param>
<param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
<param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
</init-param>
有人能理解这个吗?
更新2
它刚刚被缓存。问题解决了。
谢谢
关于java - JQuery ajax GET 请求,响应状态为 200 OK 时未触发成功,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16141867/