Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > JavaScript > Re: Order Proto...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 2 of 3 Topic 35456 of 36788
Post > Topic >>

Re: Order Prototype's Ajax.Request in a kind of Pipeline

by "Tom de Neef" <tdeneef@[EMAIL PROTECTED] > May 2, 2008 at 01:07 PM

"Kreisquadratur" <Uwe.Dauernheim@[EMAIL PROTECTED]
>
> I'm in the situation, that a user could take actions which will
> trigger several Ajax.Requests. The problem here is, that the browser
> should stay responsive, so I need the asynchronous feature but the
> responses from the server should not only have the same order as the
> requests, but I also have to wait for the first answer before I can
> send the second request. So like:
>
> Request 1
> Response to 1
> Request 2
> Response to 2
> Request 3
> Response to 3
>

The XMLHttpRequest function has a onreadystatechange property which you
can 
use to test if it has completed successfuly (readyState=4). Put your 
requests in an array and process the elements of this array in the event 
handler. Somethin like:
// req assigned to the XMLHttpRequest object
var requests = [url1,url2,url3]
requests.reverse()
req.onreadystatechange = nextRequest

function nextRequest()
{ if ((req.readyState!=4) || (requests.length==0)) return
  req.open("GET",requests.pop(),true)
}

Tom
 




 3 Posts in Topic:
Order Prototype's Ajax.Request in a kind of Pipeline
Kreisquadratur <Uwe.Da  2008-05-02 02:11:07 
Re: Order Prototype's Ajax.Request in a kind of Pipeline
"Tom de Neef" &  2008-05-02 13:07:33 
Re: Order Prototype's Ajax.Request in a kind of Pipeline
jdalton <John.David.Da  2008-05-02 08:27:06 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sun Sep 7 2:48:25 CDT 2008.