JS 测量 ajax 完成时间
JS measuring the ajax completion time
我有一个简单的 ajax 请求 js 和 php(从 mysql 获取数据)
function ajax_function(a,b) {
$.ajax({
type : 'POST',
url : mine.ajax_url,
dataType : 'json',
data : {
action : a,
},
success : b
});
};
我如何检测从初始请求到完成所花费的时间? (我正在尝试显示进度条)。
谢谢!
如果你想要进度状态:
xhr: function () {
var xhr = $.ajaxSettings.xhr(); // call the original function
xhr.addEventListener('progress', function (e) {
if (e.lengthComputable) {
var percentComplete = e.loaded / e.total;
// Do something with download progress
}
}, false);
return xhr;
}
我有一个简单的 ajax 请求 js 和 php(从 mysql 获取数据)
function ajax_function(a,b) {
$.ajax({
type : 'POST',
url : mine.ajax_url,
dataType : 'json',
data : {
action : a,
},
success : b
});
};
我如何检测从初始请求到完成所花费的时间? (我正在尝试显示进度条)。
谢谢!
如果你想要进度状态:
xhr: function () {
var xhr = $.ajaxSettings.xhr(); // call the original function
xhr.addEventListener('progress', function (e) {
if (e.lengthComputable) {
var percentComplete = e.loaded / e.total;
// Do something with download progress
}
}, false);
return xhr;
}