Whenver Ajax requests new data from the server this can sometimes take a a second or two.
Now I want to know, how can I get this time between the ajax request and the response it gets from the server?
I need this because an ajax timer I'm running ain't perfectly doing his stuff. It got some delay whenever it needs to reset to it's original time.
Thanks in Advance.
Edit: Help needed fast please, just try.
Use Firebug to see the timings for each request. http://getfirebug.com/network
This should work. Taken parts from the other example but with the ajax logic.
$(document).ready(function() {
$('#start').click(function() {
start_timer();
$.ajax({url: "/serverside.aspx", success: function(data){
stoptimer();
}});
});
});
var date1;
var start_timer = function(){ var date1 = new Date(); }
var stoptimer = function(){
var date2 = new Date();
alert('Request took: '+ date2.getTime()-date1.getTime())
}
Such as getting the current time when making the request, doing the same when getting a response and getting the difference to know the elapsed time?
What specifically is your problem? You don't know the javascript for this? If you're in that much of a hurry im guessing google would be faster than SO.
Edit
var date1 = new Date();
setTimeout(getElapsed,1000);
function getElapsed()
{
var date2 = new Date();
alert(date2.getTime()-date1.getTime());
}
This throws an alert with "1008" on my machine - this equates to milliseconds.