views:

27

answers:

1

I am at the moment making some getjson requests with jquery.

They are get requests: "GET http://localhost/MySite/JSON"

Now you can watch the requests fire in firebug. Then they return a "200 OK 250ms". I would like to be able to display something similar on my page itself. So the user can see the latency for themselves. Firebug Image Image found via google from http://testnscale.com

Is it possible to retreive the MS / Latency from a "GET" request?

+2  A: 

Just try it and check if those values you're measuring are the same or close to it.

Like

var startTime;
$.ajax({
    // .. url, type, dataType, etc
    beforeSend: function(xhr){
        startTime = +new Date();
    }
    complete: function(xhr, state){
        var latency = (+new Date()) - startTime
    }
});

I'm actually curious about that, so let us know your results. what you are getting is the difference in miliseconds.

jAndy
there is a typo in the beforeSend function . Instead of time , the variable should be startTime :)
NM
It works well. Will always be at least within 200ms in my testing 90% of the time within 40ms. Does what I'll need it to do so thankyou muchly :)
Thqr
@Ozaki: ah nice. I thought there is maybe more overhead by doing it manually.
jAndy