Merge Responses From Multiple AJAX Calls
Code snippets to show examples on merging responses from multiple AJAX calls.
HTML
<section id="output"></section>
JavaScript
$(document).ready(function() {
var dataSet1 = {
val: "First echo respxdonse"
};
var dataSet2 = {
val: "Second echo reszxcponse"
};
$.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);
});
});