Execution order with jQuery-AJAX
Posted: 02 Nov 2020, 08:15
I have this code (ajax is async):
Which outputs "world" and "hello" (in that order). But in the order I call the functions it should output "hello" and "world".
Whay is the response from the ajax function is outputed after, even it is called first?
Code: Select all
function echoHello(){
return $.ajax({
//this will return "hello";
});
}
function echoWorld(){
return "world";
}
$.when(echoHello()).done(function(response){
console.log(response);
});
console.log(echoWorld());
Whay is the response from the ajax function is outputed after, even it is called first?