JSFiddle - React, Tailwind, and code Playground
by beewayne
HTML
<div id="render-me"><div>
JavaScript
var Name = $.post('/echo/json/', {json:JSON.stringify({'name':"Brad Tate"})});
var LastUpdate = $.post('/echo/json/', {json:JSON.stringify({'lastUpdate':"Hello World"})});
$.when(Name, LastUpdate)
.done(function (nameResponse, lastUpdateResponse) {
var name = nameResponse[0].name;
var lastUpdate = lastUpdateResponse[0].lastUpdate;
$("#render-me").html(name+"'s last update was: "+lastUpdate);
})
.fail(function () {
$("#error").html("an error occured").show();
});
//Why the arrays in the done handler?
//The new done callbacks receive all the data passed to the done callback of each deferred that's being "combined" with $.when. In this case, we get two arrays - one with all the data that would have been sent to "done" callback of the name request, and one for the data returned to the lastUpdate request.