I have a JavaScript function that makes two consecutive Ajax requests using jQuery. I want to make sure that the first request has loaded before the second function is call
Edit: Misread the question; my bad. If you ever want to have two AJAX requests executed concurrently but run a callback only after both have finished, this is how you do it!
Try this:
var completedCount = 0;
var callback = function()
{
completedCount++;
if (completedCount == 2)
{
// Do something.
}
};
$.post('url-1', {}, callback);
$.post('url-2', {}, callback);