I want to measure how long it takes to process AJAX call. I have it up and running but don't know how to code this in javascript (js only)
The most simple method would be to add var ajaxTime= new Date(). getTime(); before the Ajax call and in the done get the current time to calculate how long the Ajax call took to make. var ajaxTime= new Date(). getTime(); $.
In sites that rely upon Ajax for functionality (or even pizzazz), performance becomes even more critical than the general JavaScript performance. Because Ajax requests take place behind the scenes, to the end user there is little discernible difference between an Ajax request being slow, and nothing happening at all.
The ajaxStop() method specifies a function to run when ALL AJAX requests have completed. When an AJAX request completes, jQuery checks if there are any more AJAX requests. The function specified with the ajaxStop() method will run if no other requests are pending.
var start = new Date().getTime();
doAjax({
success: function() {
var end = new Date().getTime();
console.log('milliseconds passed', end - start);
}
});
save a time value before you start doing ajax stuff, and then do it again when it finishes. Then subtract one form the other and get your time.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With