JQuery Multiple AJAX Calls Using when/then
(Tested on http://jsfiddle.net/ivan_sim/SGeA6/)
$(document).ready(function() {
var dataSet1 = {
val: "First echo response"
};
var dataSet2 = {
val: "Second echo response"
};
$.when(
$.getJSON("/echo/jsonp", dataSet1),
$.getJSON("/echo/jsonp", dataSet2)
.error(function(jqXHR, textStatus, errorThrown) {
console.log("Encounter error " + textStatus + ". " + errorThrown);
}))
.then(function(firstResponse, secondResponse) {
$("#output").append(firstResponse[0].val + ". " + secondResponse[0].val);
});
});
Written by Ivan Sim
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ivanhcsim
Authors
ihcsim
749.1K
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#