XMLhttp queuing?

D

daninbrum

Dear All,

Please excuse the following thickness, I am new to client scripting.

I have set up a page comprising of three DIVs, the content of which
gets changed by XMLHTTP requests (including the following code in a
function).

if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
document.getElementById(loc).innerHTML = xmlhttp.responseText;
}

My problem is when the page first loads. I had assumed that I could
just use onLoad to run a function that gets the data, but it gets
confused by the fact that it receives three queries in rapid
succession, before the server has had time to reply. How could I go
about queuing the requests so that they wait for one to load before the
next on triggers?

Everything works so well if I manually set up the pages - this is one
of the last hurdles I need to get through to have a promising looking
prototype. I am so impressed with how much more can be done with
JavaScript that when I last used it (a few years ago now) - no more
pages that strobe a rainbow of colours when you visit them!

I'd gratefully appreciate any advice that you (my obvious intellectual
superiors!) could provide on the issue.

Thank you kind Sirs (and Ladies),

Dan
(email not working - group reply appreciated)
 
R

RobG

(e-mail address removed) said on 03/04/2006 4:34 AM AEST:
Dear All,

Please excuse the following thickness, I am new to client scripting.

I have set up a page comprising of three DIVs, the content of which
gets changed by XMLHTTP requests (including the following code in a
function).

if ((xmlhttp.readyState == 4) && (xmlhttp.status == 200)) {
document.getElementById(loc).innerHTML = xmlhttp.responseText;
}

My problem is when the page first loads. I had assumed that I could
just use onLoad to run a function that gets the data, but it gets
confused by the fact that it receives three queries in rapid
succession, before the server has had time to reply. How could I go
about queuing the requests so that they wait for one to load before the
next on triggers?

Firstly, what is 'it' referring to in '...it gets confused'? You need
to provide some error messages. A bit more code and snippet of HTML
might help too - just enough to show the error, not your entire application.

Secondly, are you creating the xmlhttp object as a global variable
(which seems pretty common). If so, you may be over-writing it with
subsequent calls.

You can queue the requests simply by having synchronous requests where
each request calls the next one - but that defeats the purpose of
HttpRequest to a large extent.

Consider using this stuff:

<URL:http://www.ajaxtoolbox.com/>


Look in the examples, there is one for a number of simultaneous
asynchronous requests.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,584
Members
45,075
Latest member
MakersCBDBloodSupport

Latest Threads

Top