JQuery ajax GET请求,成功未触发,而响应状态为200 OK

时间:2022-06-04 20:16:11

I am having a weird response with JSON response data while sending a REST call . I can see in firebug that response status is ok, but the body is empty, even though trying with poster it works fine. Here is my JQuery call:

在发送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);

           } 
    });
}

While debugging it, it does not go to the success branch, but the error one. Here is my Resource:

在调试它时,它不会转到成功分支,而是错误一个。这是我的资源:

@GET
@Path("/totalAccountCount")
@Produces({MediaType.APPLICATION_JSON})
public JaxbWrapper<Integer> getTotalAccountCount() {
    return new JaxbWrapper<Integer>((int)this.accountStore.count());
}

I already know that reading my response with the JaxbWrapper is probably wrong, but is not hitting success at all, so for now I want to make sure this works.

我已经知道用JaxbWrapper读取我的回答可能是错误的,但根本没有取得成功,所以现在我想确保它有效。

I would appreciate some help. Thanks in advance.

我会感激一些帮助。提前致谢。

1 个解决方案

#1


0  

async: false solved it. It was jumping all the time to error function and then success

async:false解决了它。它一直跳到错误功能然后成功

Update 1

the real reason for getting it to work is because I added the following in my web.xml on the server side:

让它工作的真正原因是因为我在服务器端的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>

anyone can relate to this?

谁都可以与此相关?

Update 2

It was just cached. problem solved.

它只是缓存。问题解决了。

Thanks,

#1


0  

async: false solved it. It was jumping all the time to error function and then success

async:false解决了它。它一直跳到错误功能然后成功

Update 1

the real reason for getting it to work is because I added the following in my web.xml on the server side:

让它工作的真正原因是因为我在服务器端的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>

anyone can relate to this?

谁都可以与此相关?

Update 2

It was just cached. problem solved.

它只是缓存。问题解决了。

Thanks,