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 :)
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 :)
Share Improve this question edited Dec 29, 2012 at 13:53 Alan Tyloo asked Dec 29, 2012 at 11:20 Alan TylooAlan Tyloo 1101 gold badge3 silver badges10 bronze badges 2-
do you understand that http requests are acplished by using a
tcp connection
? http uses tcp like a fax uses a phone line.tcp connection
is what is being referred to inConnection: Keep-Alive
. You don't really know when or where the browser decides to create a tcp connection, but generally browsers will create multiple simultaneous tcp connections to a server if it would be beneficial. requests for html, images, css, ajax requests etc... all go over the same lines(although again, the browser will generally open multiple lines). – goat Commented Dec 29, 2012 at 19:08 - Thanks for the reply. Yups i know it's take place over the Tcp connection. Thanks for the clarification about the Connection: Keep-Alive. I have read that the standard is 2 simultaneous connections, though some browsers support more. – Alan Tyloo Commented Dec 29, 2012 at 20:18
1 Answer
Reset to default 2XMLHttpRequest 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/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.