tags:

views:

57

answers:

2

I am currently using this ajax queuing plugin http://www.onemoretake.com/2009/10/11/ajaxqueue-and-jquery-1-3/ and it works fine, except weh ajax call 1 finishes, ajax call 2 starts that is dependent on a value that the success functions generates when ajax 1 is complete.

Is there a way to start of all ajax calls when the previous call is complete and success function has been run?

thanks


I got it kindof working with this.. clientid triggers ajax and returns a JSON struct.. that populates building dropdown, building trigger calls another ajax but is being trigger after the first ajax call is made but before the success function is complete.. using a delay is unreliable.. any ideas?

var body = $('body');
body.queue('bodyQueue', function(){ $('#Client_ID').trigger('change');  $(this).dequeue('bodyQueue');}).delay(1000, 'bodyQueue');

body.queue('bodyQueue', function(){ $('#Building_ID').trigger('change');  $(this).dequeue('bodyQueue');});
body.dequeue('bodyQueue');

Better yet, if i can stop and start the ajax queue, that would be better, is that possible?

A: 

jQuery's AJAX library supports a completion handler (success). Put the second AJAX call in the success method of the first call, and so on.

Marcelo Cantos
is there a way to make it global as the ajax calls are dynamic and could be anything or nothing
Alessandro
Sorry, but I'm not sure what you mean by, "could be anything or nothing". AFAIK, there is no way to set up a global completion handler.
Marcelo Cantos
A: 

thanks mate..

its built around a code generator

worked around it like so..

then after the ajax and the function does what it does it calls trigger passing the ID, to trigger next in line.. bit dodgy.. but works

  triggerQ = [];
    triggerQ.push("Client_ID");
    triggerQ.push("Building_ID");
triggerNext();});

    function triggerNext(id){
    var trigger;
    if (id) {
        for(i=0;i<triggerQ.length;i++) {
            if (triggerQ[i] == id)  {
                if (triggerQ[i+1]) {
                    trigger =triggerQ[i+1];
                }
            }
        }
    } else {
        trigger = triggerQ[0];
        }
    if (trigger) $('#'+trigger).trigger('change');
    }
Alessandro