Does xmlhttprequest keep connection open after request has been processed?
XMLHttpRequest is an object which let you to request and receive data from server without refreshing the page. It uses HTTP
or HTTPS
requests. It is basically same as requesting and receiving an HTML page. You may open them synchronous or asynchronous.
XMLHttpRequest.open( Method, URL, Asynchronous, UserName, Password )
Here, Method
is HTTP
request method to use. See http://www.w3.org/TR/XMLHttpRequest/#the-open()-method
I want to handle simultaneous request.. Can i queue the request(store parameters) ..and in the onreadystate provide function to handle it.. i.e. calling the function that make request recursively? or it's not a good idea at all?
I'd make an array of XMLHttpRequests and handle data and remove XMLHttpRequest from array onreadystatechange
. Keep in mind that you will receive a mixed order of asynchronous responses or may not receive a response at all.
When is the connection closed..at what stage?
It is closed right after data is received. Note that keep-alive
is about keeping the session alive, not the connection.
Alan Tyloo
Updated on June 08, 2022Comments
-
Alan Tyloo almost 2 years
I have done a simple ajax...
The request and response header both contain the Connection:
Keep-Alive
I goggle a bit and saw that the client thus maintain a persistent connection with the server. This support pipelining, where client may send multiple request without waiting for each response.
So i have some questions:
- Where does the xmlhttprequest actually open a connection to the server?
- Does creating many xmlhttprequest object open their own connect or it send it on a same connection using pipelining...?
- I want to handle simultaneous request.. Can i queue the request(store parameters) ..and in the onreadystate provide function to handle it.. i.e. calling the function that make request recursively? or it's not a good idea at all?
- When is the connection closed..at what stage?
Other info: I don't want to use jquery or any other librarie for the ajax.You can propose though. i can check how they work. I'm using javascrip and php(codeigniter framework). I want to be able to handle multiple request(2)..and queue request that are made when the limit has been reached.
Thanks in advance :)
-
Alan Tyloo over 11 yearsNot by me. Thanks for the reply. I'am going to check more on it.
-
Ertug over 11 yearsAlan, you are welcome. I am just curious because if there is something wrong in my answer, I don't want to mislead anyone with it and I'd like to learn from my mistake.
-
Orwellophile about 10 years@Ertug > "Note that keep-alive is about keeping the session alive, not the connection." Untrue. It's all about keeping the (TCP) connection alive. There is no such thing as a "session."
-
pavel_karoukin over 8 years@Orwellophile, depending on how you treat it, TCP is session over IP :)
-
Orwellophile over 8 years@pavel_karoukin, agreed. but http is 1 or more sequential (and partially parallel) transactions over that tcp layer.
-
Eric Spreen over 8 years@pavel_karoukin Technically I would have to disagree. TCP is a transport mechanism (Layer 4) over IP, that provides a reliable connection. Setting up a new TCP connection brings overhead with it, so you want to keep it open as much as possible. A session would live right on top of a TCP connection (Layer 5) and is in general not applicable to HTTP request, since HTTP generally operates on the Application Layer (7). So,
keep_alive
is all about keeping the connection alive if possible. Just the HTTP request gets closed.