I'll get straight to the point!
My javascript sends about 20 AJAX requests to my PHP file to respond to (via an external web API) when the user submits their search. The results are stored in an array in the session array.
I've read that browsers will only allow 2 simultaneous requests to a server.
My first problem is that while there are still more than one requests still waiting for a response the AJAX "add to basket" request won't work since it's still waiting for the other requests to complete.
My second (and more annoying) problem is that the 2 requests that are being handled simultaneously seem to be over writing each other so that when all the responses are complete only half are in the session array. Either all the odd ones or even ones depending on whether the final request is odd or even.
I'd prefer not to have to send requests individually (ie only send the next when the last has finished) as that would slow things down for the user a fair bit.
Is there a solution to this session overwriting or should I be using a completely different approach altogether?
Thanks all!
Edit:
It's for checking domain availability. The user searches for "mydomain" and results for com, net, org, etc are eventually presented.
Sending a single request and having the script search for all tlds in one go means that a response isn't returned until all results are in. The result for some tlds seem to take upto and over 30 seconds during which the user is getting no feedback save for a swirly icon and "Please Wait" (this is what happens when javascript isn't enabled).
Seperate requests allow me to display the domains availability as they come in.
I'm currently thinking along the lines of sending a single request and then using javascript's setinterval to repeatedly check the session until all results are in.