我试图找到关于以下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 falseajax 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.

Jquery相关问答推荐

JQuery DateTimePicker-在 Select 中抓取星期几

无法通过单击从元素获取数据

是否可以从不可见的 DataTables 列访问数据?

在函数 jQuery 中更改语言

使用带有 bootstrap 验证的 Ajax 函数时出现问题

如何使用 jQuery 强制悬停状态?

缺少 .map 资源?

如何从 jQuery 转到 React.js?

如何在 jQuery 中获取浏览器滚动位置?

jQuery ajax() 使用成功、错误和完成与 .done()、.fail() 和 always()

jQuery绑定到粘贴事件,如何获取粘贴的内容

聚焦 时防止 iphone 默认键盘

blueimp 文件上传插件中的 maxFileSize 和 acceptFileTypes 不起作用.为什么?

如何在我的 WordPress 插件中包含 CSS 和 jQuery?

验证外部脚本是否已加载

好处和.在本地托管 jQuery 的trap

使用 jQuery 的 ajax 方法将图像作为 blob 检索

检测夹点的最简单方法

在jQuery中获取CSS规则的百分比值

jquery追加到列表的前面/顶部