开发者

Ajax Requests Never Return on Certain Browsers

开发者 https://www.devze.com 2023-03-28 10:14 出处:网络
I have been debugging an ajax issue for a week and cannot figure out how to fix it.I am using jquery to make the ajax call as follows:

I have been debugging an ajax issue for a week and cannot figure out how to fix it. I am using jquery to make the ajax call as follows:

.... in head tag....
$.ajaxSetup({
cache: false
});

 ....on button click in the code...
jqxhr = $.ajax({
      url: 'searching.html',
      data: 'showDetails=' + showProgressDetails,
      dataType:'text',
      success: handleRefreshComplete,
      error:handleSearchError,
      complete:handleCompleteEvent
    })    
    .done(function() { alert("done"); 开发者_StackOverflow中文版})
    .fail(function() { alert("error"); })
    .always(function() { alert("always"); });

The ajax call takes about 5 minute to complete. When I run this code in Chrome it works, but all other browsers just sit there and never complete. No errors are thrown and none of the event handlers (e.g. error, success) are called.

I have used WireShark to look at the network trace and i see that when the ajax calls are made in Chrome, there are TCP keep alive requests being sent like this:

...[TCP Keep-Alive] 64428 > http [ACK] Seq=3599 Ack=135557 Win=40018 Len=1
...[TCP Keep-Alive ACK] http > 64428 [ACK] Seq=135557 Ack=3600 Win=248 Len=0 SLE=3599 SRE=3600

For all the other browsers, there are none of these being sent and received. I have tried setting timeouts, but they don't seem to have any effect on the code.

The problem is actually more complex than I at first thought. It appears that the issue happens when there is more than one ajax request on our network. When this happens, Chrome works great, but the other browsers just wait indefinitely. On the server side, all the calls return back to the client

Any thoughts or suggestions on how to fix or further debug this issue would be greatly appreciated.

Thanks,

Joe C


Try adding a timeout to your call:

Here I added a timeout of 5 minutes (5 * 60 * 1000)

$.ajaxSetup({
   cache: false,
   timeout: 3000000
});

You may want to bump it up a notch higher depending on the actual time it takes.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号