I’m using jQuery deferred objects so I can pull data from multiple sources , however not sure how best to code in a loading message that displays whilst everything is being resolved and then hides when everything is resolved OR rejected
CURRENT CODE:
jQuery.when(loadData('ws-get-shops.php', {shopId:123}),loadData('ws-get-customers.php')).then(updateResults,showError);
var loadData = function(url, data){
var jqxhr = jQuery.ajax({
url:url,
data:data,
dataType:'jsonp',
timeout:60000
});
return jqxhr;
}
You can add (or show) the loading message right before you start the ajax calls, like:
and then delete (or hide) it in the
updateResultsandshowErrorfunction when they finish, like:You can also add another function as the third parameter to the
thenfunction which is called when thewhenfunction makes progress and update your loading message to show a percentage or something.Reference: http://api.jquery.com/deferred.then/