Jquery Promise Example
HTML
<div id="container">
<h1>Testing Jquery Promise</h1>
</div>
JavaScript
$("#container").append("<div class='spinner'>");
$.when(setTimeout(function(){
alert("Boom!");
}, 2000)).then(function() {
// both AJAX calls have succeeded
console.log('SUCCESS');
}, function() {
// one of the AJAX calls has failed
console.log('FAIL');
}, function() {
console.log('FINALLY');
$("#container").remove(".spinner");
});