I have this code (ajax is async):
function echoHello()
{
return "hello";
}
function echoWorld()
{
return $.ajax({
//this will return "world";
});
}
console.log(echoHello());
$.when(echoWorld()).done(function(response)
{
console.log(response);
});
which outputs "hello" and "world" (in that order). But if change it a little bit, so the console.log()
is in different order:
function echoHello()
{
return "hello";
}
function echoWorld()
{
return $.ajax({
//this will return "world";
});
}
$.when(echoWorld()).done(function(response)
{
console.log(response);
});
console.log(echoHello());
is the same output guaranteed? Or it could potentially output "world" and then "hello"?
from execution order with jQuery's AJAX
No comments:
Post a Comment