我试图找到关于以下jQuery函数的更多信息:
jQuery.active
It is described to test the number of active connections to a server and will evaluate true when the number of connections is zero.
我在jQuery网站上找不到关于这个功能的任何信息,我想知道是否有人知道我可以在哪里使用它.
我试图找到关于以下jQuery函数的更多信息:
jQuery.active
It is described to test the number of active connections to a server and will evaluate true when the number of connections is zero.
我在jQuery网站上找不到关于这个功能的任何信息,我想知道是否有人知道我可以在哪里使用它.
This is a variable jQuery uses internally, but had no reason to hide, so it's there to use. Just a heads up, it becomes jquery.ajax.active
next release. There's no documentation because it's exposed but not in the official API, lots of things are like this actually, like jQuery.cache
(where all of jQuery.data()
goes).
I'm guessing here by actual usage in the library, it seems to be there exclusively to support $.ajaxStart()
and $.ajaxStop()
(which I'll explain further), but they only care if it's 0 or not when a request starts or stops. But, since there's no reason to hide it, it's exposed to you can see the actual number of simultaneous AJAX requests currently going on.
When jQuery starts an AJAX request, this happens:
if ( s.global && ! jQuery.active++ ) {
jQuery.event.trigger( "ajaxStart" );
}
这就是引发$.ajaxStart()
事件的原因,连接数从0变为1(jQuery.active++
在这之后不是0,!0 == true
),这意味着当前simultaneous个请求中的第一个已启动.同样的事情也发生在另一端.当AJAX请求停止时(因为a beforeSend
abort via return false
或ajax call complete
function runs):
if ( s.global && ! --jQuery.active ) {
jQuery.event.trigger( "ajaxStop" );
}
This is what causes the $.ajaxStop()
event to fire, the number of requests went down to 0, meaning the last simultaneous AJAX call finished. The other global AJAX handlers fire in there along the way as well.