If $
is jQuery, you can add an ajaxComplete
callback, and check if $.active
inside:
(如果$
是jQuery,则可以添加ajaxComplete
回调,并检查$.active
在其中:)
$(document).on('ajaxComplete', () => {
Promise.resolve().then(() => {
if (!$.active) {
console.log('All done');
}
});
});
It's not a single line of code, but it should work.
(它不是一行代码,但是应该可以。)
(You can test it by running this in the console, then opening your inbox or reputation record in Stack Overflow's topbar. An ajax request will be sent out, and when it's complete, ajaxComplete
will run, and $.active
will get set to 0)((您可以通过在控制台中运行它来进行测试,然后在Stack Overflow的ajaxComplete
打开收件箱或信誉记录ajaxComplete
请求将被发送出去,完成后, ajaxComplete
将运行,并且$.active
将被设置为0 ))
The Promise.resolve().then
is needed because $.active
gets decremented only after the ajaxComplete
callback runs.
(Promise.resolve().then
是必需的,因为$.active
仅在 ajaxComplete
回调运行后才递减。)
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…