I am making an AJAX request that updates the value of a variable (foo
) with a response from the server. Here is the code I am using:
The issue is simple...
alert(foo);
will execute while the request is being processed and foo
will not be altered yet.
if you do :
$.ajax({
url: "/",
dataType: "text",
success: function(response) {
foo = "New value:" + response;
alert(foo);
},
error: function() {
alert('There was a problem with the request.');
}
});
You'll see that it's working as intended