In the following jquery function, can someone explain to me why "second" is being executed before "first"? I assume that the entire $.post request should be completed before the browser moves on to the next line of code, but that does not appear to be happening.
function getGUID () {
$.post(getGUIDScript, function(data, textStatus) {
alert("first");
GUID = data;
},
'text');
alert("second");
}
Thanks for the responses below guys. For posterities sake, the code above can be written as is shown below to wait until the post is completed before moving on.
function getGUID () {
$.ajax({
type: "POST",
url: getGUIDScript,
async: false,
success: function(data) {
alert("first");
GUID = data;
}
});
alert("second");
}
This will set off the first alert and then the second.