Use of $ Promises
combine 2 ajax calls
by Exceeder
HTML
Hi!
<div id="message">wait...</div>
<div id="stamp">!</div>
JavaScript
/*$.post("/echo/json", {"test":"hello"}, function(data) {
$('#message').text("Response @"+new Date().getMilliseconds() + " " + JSON.stringify(data));
}, 'json');*/
function echoJson() {
return $.post("/echo/json", {"test":"hello"});
}
function echoJson2() {
return $.post("/echo/json", {"test2":"hello2"});
}
$.when(echoJson(), echoJson2()).then(
function(data) {
$('#message').text("Response @"+new Date().getMilliseconds() + " " + JSON.stringify(data));
}
);
$('#stamp').html("::: "+new Date().getMilliseconds());