获取AJAX请求持续时间 [英] Getting AJAX Request Duration
问题描述
我想使用jquery获取某个ajax请求的持续时间.例如,我正在使用此脚本:
I would like to get the duration for a certain ajax request using jquery. For instance I am using this script:
$.ajax({
type: "GET",
url: "http://localhost/thescript.php",
success: function(data){
$("#container").html(data);
},
complete: function(jqXHR, textStatus){
alert("http://localhost/thescript.php took 'n' seconds to load");
}
});
我想知道这个Ajax脚本加载URL"http://localhost/thescript.php"多长时间.例如,警报:"http://localhost/thescript.php的加载时间为'n'秒".
I would like to be able to know how long this ajax script loaded the url "http://localhost/thescript.php". For instance alert: "http://localhost/thescript.php took 'n' seconds to load".
推荐答案
您可以使用beforeSend()
和complete()
函数比较当前时间戳并计算差异.
You can use the beforeSend()
and complete()
functions to compare the current timestamps and calculate the difference.
http://api.jquery.com/jQuery.ajax/
在这里您可以看到$.ajax
提供的所有回调挂钩:
http://api.jquery.com/jQuery.ajax/#callback-functions
Here you can see all callback hooks provided by $.ajax
:
http://api.jquery.com/jQuery.ajax/#callback-functions
这篇关于获取AJAX请求持续时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!