Is the Ajax connection disconnected at some point?

My co-worker told me that the AJAX connection lives on until the user closes his browser. As far as I know, an ajax connection closes its connection when its request is complete. I tested it with Firebug and the HTTP monitoring tool, I noticed that the AJAX connection was closing.

Is he right?

+1
source share
5 answers

Break that AJAX - and XMLHttpRequest. This is the connection to the URI endpoint for some resource (image, text, etc.). Your browser closes the HTTP connection as soon as it is done.

+1
source

Ajax, just like any other request, closes when it finishes the connection. Your colleague is wrong.

Note. There are connection types that allow unlimited communication

+3
source

Ajax connections are closed after receiving data or closed by a tab, then the connections will be forced to close.

The Ajax life cycle is described here .

+1
source

Late to the party here, but it concerns the problem that I am now facing ...

I have a web server running on a platform with limited resources (128k Flash, 48k RAM), so it can only process one connection at a time. Further connections are not processed until the current one is closed. Also, it does not force Connection: close on certain URLs due to the low latency requirement. In general, only one thing is talking at the same time with the device.

AJAX connections comply with any rules that the browser sets for other connections. In my case, I am testing a webpage that uses AJAX to read one of the URLs supported in live mode once per second, and the browser does not close the connection until a few seconds after the window closes. As a result, other customers wait indefinitely.

So, do not assume that the XHR connections are closed upon completion. They may not be like that; Firefox 21 does not close them.

My current problem is that I want my AJAX requests to close the socket upon completion, and I use jQuery .ajaxSend() pre-send hook to set the Connection: close header. AJAX seems to work, but when another client tries to connect, it gets a “reset from peer connection”, so I wonder if Firefox noticed the “Connection: close” header in the XHR request and keeps its socket end open (until it expires) after about three seconds) even after the server has closed its side.

0
source

Using jQuery to execute AJAX requests, some connections are supported until the next AJAX call. This can be a real problem when the server keeps the threads open until a close response event occurs.

0
source

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


All Articles