discuss  

Re: [jQuery] Abort XMLHttpRequest

Jörn Zaefferer
Fri, 29 Sep 2006 12:26:55 -0700

Mike Chabot schrieb:
> I want to either abort all previously running Ajax requests or force
> the requests to return in the order that they were called. What is the
> best way to accomplish this?
>   
You could put the returning values in a queue. To guarantee the order, 
you could send a counter that is increased with every request, return 
that counter value and use it for restore the order while processing the 
queue. Some basic functions to start with could look like this:

function synchronize(callback) {
    queue[queue.length] = callback;
    if(!blocking) {
        process();
    }
}

function process() {
    while(queue.length && !blocking) {
        var call = queue[0];
        queue = queue.slice(1);
        call();
    }
}

-- Jörn

_______________________________________________
jQuery mailing list
discuss@jquery.com
http://jquery.com/discuss/
  • Re: [jQuery] Abort XMLHttpRequest Jörn Zaefferer