Here\'s an contrived example of what\'s going on: http://jsfiddle.net/adamjford/YNGcm/20/
HTML:
Click me!
&l
When calling multiple parallel AJAX calls, you have two options for handling the respective responses.
Promises'
array and $.when which accepts promise
s and its callback .done
gets called when all the promise
s are return successfully with respective responses.Example
function ajaxRequest(capitalCity) {
return $.ajax({
url: 'https://restcountries.eu/rest/v1/capital/'+capitalCity,
success: function(response) {
},
error: function(response) {
console.log("Error")
}
});
}
$(function(){
var capitalCities = ['Delhi', 'Beijing', 'Washington', 'Tokyo', 'London'];
$('#capitals').text(capitalCities);
function getCountryCapitals(){ //do multiple parallel ajax requests
var promises = [];
for(var i=0,l=capitalCities.length; i
Capital Cities :
Respective Country's Native Names :