I have some javascript code that makes an ajax call, get's a var and then attempts to use the var later in the script. The problem is because of the ajax call, the rest of the code is running before it has the var. If I simply add in an alert, things work fine:
var quote_request_id;
$.ajax({
type: "POST",
url: rate_url + '/99/1',
data: datastring,
dataType: "html"
}).done( function(data,status,xhr) {
quote_request_id = xhr.getResponseHeader('X-QuoteRequest-Id');
});
I then have other ajax calls that uses the quote_request_id var but it isn't being set. If I simply add in an alert after the block of code above, it works. I realize it's because of the asynchronous behavior of the ajax call. Just need to figure out a way to get the var and use it in the rest of the code.