On 2/1/06, Frank W. Zammetti <[EMAIL PROTECTED]> wrote: > Wendy Smoak wrote: > > On 2/1/06, Michael Jouravlev <[EMAIL PROTECTED]> wrote: > > > >> Hi, Ajax gurus, I have an OT question: how to ensure the proper order > >> of several XHRs? I found how to create several XHRs simultaneously, > >> but I have a requirement: to wait for the first request to return > >> before firing the second, > > > > (Hardly an expert but...) the third parameter of > > XMLHttpRequest.open(...) is a flag that says whether the request > > should be asynchronous. It's usually true. Set it to false and I > > think it will block until the response is received. Frank will now > > correct me if I'm wrong. :) > > > > And lets move to the user list if this gets any further off topic, shall we? > > > > -- > > Wendy > > > No Wendy, you are correct in your explanation :) I see Ajax in Action > is serving you well :) > > I wouldn't expect it to be the best answer though because that parameter > blocks *all* Javascript, not just further XMLHttpRequest's.
Exactly. This is the reason why I don't want to use this flag. I also have heard that if server fails to respond, then browser can simply hang up so I would have to restart it. This will not work for me :) > What you will probably want to do Michael is build up a queue on the > client and write some code to ensure the order the handlers fire. This > could be pretty tricky to say the least. > > Take a look at the RequestSender tag in AjaxTags in Java Web Parts... > AjaxTags builds up such a queue so that multiple requests can fire > simultaneously without stepping on each other. I borrowed code from http://www.xml.com/cs/user/view/cs_msg/2815 to make simultaneous XHRs. Works well. I even understand now *how* it works :) > I suspect you would be > able to extend this to ensure firing order. Yep, this is the problem. I will look at your code for ideas ;-) > Off the top of my head, I > would think you would need to set up a timer, and when the responses > come back, instead of processing them on the spot in the callback, > instead set a flag in the call structure that says "yes, this request > completed, but don't process it until the previous one completes"... > fire the timer every half a second or something like that to examine all > the call structures in the queue and fire them as appropriate. Nah, this won't work. I need to fire second XHR only after the first one returns. The reason is that first request updates server status and I want second request to pick it up. I will think about firing requests on timer. Seems like this is the only way. Or maybe I can stick request number into request parameters, and reorder requests on server? In this case I will need total number of requests too. TCP/IP somehow does this kind of thing, right? Should have to read more about it ;-) In my case I always fire *all* requests, so TCP/IP should be a good exaple to look at. > Probably not a trivial exercise, but should be doable. I hope so. I will keep this discussion in public list in case someone else decides to chime in. P.S. I should have seen the "Struts-dev" label that I assign to dev list emails, but apparently I haven't ;-)) Michael. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]