Wait function for lots of AJAX on page

Soldato
Joined
5 Dec 2003
Posts
2,716
Location
Glasgow
Hey I have a lot of AJAX refreshing stats on a single webpage and having a problem whereby some of the info returned is appearing in odd places in the wrong DIVs. I reckon this is because there is a few firing off at once so need to build a sort of queue or waiting system so that one AJAX request finishes before another starts. Has anyone any experience of this or know how I ought to go about it?
 
Hey I have a lot of AJAX refreshing stats on a single webpage and having a problem whereby some of the info returned is appearing in odd places in the wrong DIVs. I reckon this is because there is a few firing off at once so need to build a sort of queue or waiting system so that one AJAX request finishes before another starts. Has anyone any experience of this or know how I ought to go about it?

You could try using setInterval or use a plugin called 'ajax queue' - http://plugins.jquery.com/project/ajaxqueue
 
Its worth pointing out that AJAX isn't supposed to work with queues.

Fundamentally its aynchronous. You should expect to fire off calls in the order 1 2 3 4 5, and them come back in any order.

A better approach that forcing a queue in, which might end up harming performance, calls waiting to be processed etc would be to ensure that the correct div is used once the call returns. An easy way to do this would be to pass in the div id and return it unchanged from the call to be used on the client to set the content.
 
Last edited:
Back
Top Bottom