AJAX long poll not sent from browser

I have a javascript web application configured to use long polls with a .net server using ajax call:

var _listenTimeout = 5 * 60 * 1000; //... $.ajax({ type: "GET", url: url, async: true, cache: false, dataType: "jsonp", timeout: _listenTimeout, success: callback }); 

However, a problem occurs when the page is open for a while, when server requests stop responding. It seems to be in a state of uncertainty when packets get stuck between a web browser and are sent from the network to the server.

I dug, and I know a couple of things:

  • The request is sent because it is displayed on the network tab of the Chrome web browser (also chrome: // net-internals) and firebug. The request status is always waiting, and it just stops in this state.
  • The request url is correct because sending the same url via curl returns an immediate response.
  • It did not leave my network because there were no packets detected using wireshark . Server logs (and wirehark on the other side) also show nothing.

Strange, sometimes it works sporadically, but with a delay of a couple of minutes, i.e. in the browser's network log, it is detected that the request receives a response (204 in my case), and wirehark detects the sent request (and received on the server). The delay is the same for both the browser and wirehark, i.e. The request is executed, a delay occurs, then the chrome detects a response and the proxy server detects the sent packets.

A clean page refresh also fixes the problem, and the same request / response occurs almost immediately (with the corresponding browser network and protocol logs).

I tried it on Chrome 21.0.1180.89 and Firefox 14.01.

Is there some kind of browser queue that gets blocked in the browser using ajax requests? Or maybe too many simultaneous requests ? I don’t know now ...

+4
source share
1 answer

$. ajax will not execute periodic requests. timeout determines the delay in accepting the actual request, not for polling. read about it here. http://api.jquery.com/jQuery.ajax/ . This is why you see only one ajax request. If you want it manually, you must do this using the setTimeout javascript method.

You can call setTimeout on successful and error callbacks so you can get rid of concurrent ajax requests.

0
source

Source: https://habr.com/ru/post/1435107/


All Articles