jQuery.active

博客提到2019独角兽企业招聘Python工程师标准,重点围绕ajaxuploadfile组件展开。作者看其源码时遇到不明内容,官方文档和网上资料少,在特定英文地址找到有用信息,还给出ajaxfileupload里的源代码,并建议进一步了解可参考jQuery的ajax源码及对应传送门。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

参考原地址:http://stackoverflow.com/questions/3148225/jquery-active-function

在看ajaxuploadfile组件原码的时候遇到的,不知道是什么东西,官方文档里也找不到,网上资料也很少,最后在这里找到点有用的,不过全是英文。

ajaxfileupload里的源代码(这个貌似jquery 的ajax源码里也有);

if ( s.global && ! jQuery.active++ )
{
	jQuery.event.trigger( "ajaxStart" );
}

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" );}

This is what causes the $.ajaxStart() event to fire, the number of connections just went from 0 to 1 (jQuery.active++ isn't 0 after this one, and !0 == true), this means the first of the current simultaneous requests started. The same thing happens at the other end. When an AJAX request stops (because of a beforeSend abort via return false or an 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.

看不懂的找度娘吧,这里就不秀本人捉急的英文了。

如果想进一步了解可以参考jQuery的ajax源码

 传送门:https://github.com/jquery/jquery/blob/master/src/ajax.js

转载于:https://my.oschina.net/u/912810/blog/308728

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值