如何计算 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
}
关于php - AJAX响应时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5728833/