Javascript callback for multiple ajax calls

Posted by Jisaak on Stack Overflow See other posts from Stack Overflow or by Jisaak
Published on 2010-12-06T17:02:39Z Indexed on 2011/01/10 8:53 UTC
Read the original article Hit count: 392

Filed under:
|
|
|

My lack of javascript knowledge is getting me in trouble again. I think this should be a fairly easy problem to fix but I cant figure it out.

Situation: I want to make three ajax calls in a click event. Each ajax call does a distinct operation and returns back data that is needed for a final callback. The calls themselves are not dependent on one another, they can all go at the same time, however I would like to have a final callback when all three are complete.

$('#button').click(function() {
    fun1();
    fun2();
    fun3();
//now do something else when the requests have done their 'sucess' callbacks.
});

var fun1= (function() {
    $.ajax({/*code*/});
});
var fun2 = (function() {
    $.ajax({/*code*/});
});
var fun3 = (function() {
    $.ajax({/*code*/});
});

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery