Reputation: 5611
I have a simple ajax request for js and php (fetching data from mysql)
function ajax_function(a,b) {
$.ajax({
type : 'POST',
url : mine.ajax_url,
dataType : 'json',
data : {
action : a,
},
success : b
});
};
How would I detect the time that it takes from the initial request to the completion? (I am trying to show progress bar).
Thanks!
Upvotes: 2
Views: 70
Reputation: 6145
If you want progress status:
xhr: function () {
var xhr = $.ajaxSettings.xhr(); // call the original function
xhr.addEventListener('progress', function (e) {
if (e.lengthComputable) {
var percentComplete = e.loaded / e.total;
// Do something with download progress
}
}, false);
return xhr;
}
Upvotes: 2