I have an array with some URLs inside, and I want to get their HTML and push it into another array (or JSON or something else).
The code looks like this;
url = ["/page_1.html", "/page_2.html"];
received_data = [];
function() {
url.each(function(i) {
$.ajax({
type: 'GET',
url: this,
success: function(data) {
received_data.push(data);
}
});
});
// send received_data to some other server
};
The problem is that this code will not wait for the ajax() requests and start sending received_data empty. How to wait until all ajax() requests end (except using synchronous requests) ?