AJAX响应时间 [英] AJAX response time

查看:119
本文介绍了AJAX响应时间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何计算AJAX响应时间?我需要在脚本中使用它,因为我得到了服务器时间戳,但如果请求需要1秒以上,我需要在时间戳上加1秒!

How I can calculate AJAX response time? I need this in script, because I get back the server timestamp, but if the request take more than 1 second I need to add 1 second to the timestamp!

推荐答案

您需要获取开始时间(就在AJAX请求完成之前),然后是脚本完成的结束时间。你可以解决这个差异,如果它超过60秒,你可以做你的事。

You need to get the start time (just before the AJAX request is done), and then the end time when the script is complete. You can than work out the difference, and if it's greater than 60 seconds, do your thing.

//Before the AJAX function runs
var startTime = new Date().getTime();

//Place this code inside the success callback of your AJAX function
var endTime = new Date().getTime();
if ((endTime - startTime) > (60 * 1000)) {
    //Took longer than 60 seconds
}

这篇关于AJAX响应时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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