Let us assume we need to hit a lot of URLs to append data to a page this so to reduce the time we need to make these requests simultaneous.
The below code contains an array of JSON values
these JSON values are URL and respective id
URL is tho fetch data and ID is to append data
s = [{
url : "url1",
id : "id1"
},{
url : "url2",
id : "id2"
},{
url : "url3",
id : "id3"
},{
url : "url4",
id : "id4"
}]
now calling all these URL in .each()
$(s).each(function() {
var url = this.url, id = this.id;
$.getJSON(url, {id: id }).done( function(data) {
$(data.id).append(data.value)
});
})