JQuery ajax GET请求,响应状态为200 OK时成功没有触发

时间:2013-04-22 07:44:38

标签: java jquery ajax json rest

我在发送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 个答案:

答案 0 :(得分:0)

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

它刚刚被缓存。问题解决了。

谢谢,

相关问题