是否有可能从"GET"服务器中检索MS/等待时间.要求? (Javascript/Jquery) [英] Is it possible to retrieve the MS / Latency from a "GET" request? (Javascript / Jquery)

查看:126
本文介绍了是否有可能从"GET"服务器中检索MS/等待时间.要求? (Javascript/Jquery)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在正在用jquery发出一些getjson请求.

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

它们是获取请求:"GET http://localhost/MySite/JSON "

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

现在您可以在Firebug中观看请求触发.然后,他们返回"200 OK 250ms" . 我希望能够在页面本身上显示类似的内容.因此,用户可以自己看到延迟. Firebug图片http://testnscale.com/blog/wp- content/uploads/2009/12/firebug.png 通过Google从 http://testnscale.com

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

是否可以从"GET"请求中检索MS/等待时间?

推荐答案

只需尝试一下,然后检查您要测量的值是否相同或接近.

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

喜欢

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.

这篇关于是否有可能从"GET"服务器中检索MS/等待时间.要求? (Javascript/Jquery)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆