开发者

Is it possible to retrieve the MS / Latency from a "GET" request? (Javascript / Jquery)

开发者 https://www.devze.com 2023-01-05 04:05 出处:网络
I am at the moment making some getjson requests with jquery. They are get requests: \"GET http://localhost/MySite/JSON\"

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 http://testnscale.com/blog/wp-content/uploads/2009/12/firebug.png Image found via google from http://开发者_如何转开发testnscale.com

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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消