how do i get ajax to call after previous success is complete
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 开发者_StackOverflow社区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?
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.
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');
}
精彩评论