如何计算 AJAX 响应时间?我在脚本中需要这个,因为我得到服务器时间戳,但如果请求花费超过 1 秒,我需要在时间戳上添加 1 秒!
您需要获取开始时间(就在 AJAX 请求完成之前),然后获取脚本完成时的结束时间。然后您可以计算出差异,如果大于 60 秒,则执行您的操作。
//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
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)