Có lẽ không có sự khác biệt, nhưng là một trong hai cách tốt hơn so với người kia (hoặc có lẽ là một bí ẩn 'ba' cách tốt hơn so với cả hai!) ...jQuery tôi nên sử dụng nhiều ajaxStart/ajaxStop xử lý
đầu tiên:
var startTime;
$(document).ready(function() {
$("#lbl_ajaxInProgress").ajaxStart(function() {
// store the current date/time...
startTime = new Date();
// update labels
$(this).text('Yes');
$("#lbl_ajaxCallTime").text("-");
});
$("#lbl_ajaxInProgress").ajaxStop(function() {
// update labels
$(this).text('No');
$("#lbl_ajaxCallTime").text(myFunctionThatCalculatesTime(startTime));
});
});
thứ hai:
var startTime;
$(document).ready(function() {
$("#lbl_ajaxInProgress").ajaxStart(function() {
// update labels
$(this).text('Yes');
});
$("#lbl_ajaxInProgress").ajaxStop(function() {
// update labels
$(this).text('No');
});
$("#lbl_ajaxCallTime").ajaxStart(function() {
// store the current date/time...
startTime = new Date();
// update labels
$(this).text("-");
});
$("#lbl_ajaxCallTime").ajaxStop(function() {
// update labels
$(this).text(myFunctionThatCalculatesTime(startTime));
});
});
Tính đến jQuery 1.8, phương pháp này .ajaxStart() nên chỉ được gắn liền với tài liệu. – ThdK