tw36_q
Last Updated: February 25, 2016
·
1.776K
· ihcsim
130921 tcl 103 s

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);
  });
});​
Say Thanks
Respond
Awesome Job

20838750 ca12 11e7 8395 3d07316c018d
Overijssel,Amsterdam, Arnhem
·
Overijssel, Amsterdam, Arnhem
·
Full Time