gpt4 book ai didi

javascript - ajaxStart() 只被调用一次,而 ajaxComplete() 被调用多次

转载 作者:数据小太阳 更新时间:2023-10-29 05:55:28 25 4
gpt4 key购买 nike

我想对我页面上的每个 AJAX 请求调用做一些事情。

我读了here那个

ajaxStart (Global Event)

This event is broadcast if an Ajax request is started and no other Ajax requests are currently running.

ajaxComplete (Global Event)

This event behaves the same as the complete event and will be triggered every time an Ajax request finishes.

这意味着我只能跟踪一个 ajax 事件的开始,而不是每个单独的请求?

$(document).ajaxStart(function () {
var t = new Date(),
h = t.getHours(),
m = t.getMinutes(),
s = t.getSeconds(),
ms = t.getMilliseconds();
console.log("Triggered ajaxStart handler at " + h + ":" + m + ":" + s + ":" + ms);
});


$(document).ajaxComplete(function () {
var t = new Date(),
h = t.getHours(),
m = t.getMinutes(),
s = t.getSeconds(),
ms = t.getMilliseconds();
console.log("Triggered ajaxComplete handler at " + h + ":" + m + ":" + s + ":" + ms);
});

给我

Triggered ajaxStart handler    at 11:14:33:409 
Triggered ajaxComplete handler at 11:14:33:480
Triggered ajaxComplete handler at 11:14:33:489
Triggered ajaxComplete handler at 11:14:33:491
Triggered ajaxComplete handler at 11:14:33:492
Triggered ajaxComplete handler at 11:14:33:535
Triggered ajaxComplete handler at 11:14:33:539
Triggered ajaxComplete handler at 11:14:33:567
Triggered ajaxComplete handler at 11:14:33:569

有什么方法可以记录每个 ajax 启动,以便我可以将 even 附加到每个 ajax 事件?

最佳答案

你想要 .ajaxSend事件,为每个 AJAX 请求发送,而不仅仅是第一个未完成的请求。

关于javascript - ajaxStart() 只被调用一次,而 ajaxComplete() 被调用多次,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15072669/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com