Hi
I am trying to call two user defined functions and expecting the first one has to execute first and then the second one.. but they are executing simultaneously.
$.firstfunc = function(){
//Do something
//jQuery.ajax({
});
$.secondfunc = function(){
//Do something
jQuery.ajax({
});
$.(document).ready(function(){
$.firstfunc();
$.secondfunc();
});
any help would be appreciated.
Thanks!
Warning: Requires jQuery 1.5+
Using the black magic of
$.Deferred‘s and$.when.It basically says when you first function finishes its ajax call then call the second function.
This is because
$.ajaxreturns ajqXHRobject which inherits from$.Deferred.If you want to attach a callback when both
$.firstfuncand$.secondfunccomplete then you can do the following (requires jQuery 1.6):Legacy: jQuery 1.4.2 & 1.3.2 support.