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

家住魔仙堡 提交于 2019-12-10 10:51:56

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/3155960/is-it-possible-to-retrieve-the-ms-latency-from-a-get-request-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!