$ .active在遵循jQuery代码中意味着什么?

PHP*_*Fan 5 jquery

我在我的项目中使用了以下jQuery库.以下是添加它们的代码:

<script src="jquery-1.9.1.min.js"></script>
    <script src="jquery-ui-1.10.0.custom.min.js"></script>
Run Code Online (Sandbox Code Playgroud)

现在由以前的开发人员编写的函数如下:

function add_rebate_by_product() {
  if($.active > 0) { //or $.active  //What this $.active does   
    request_inprogress();
  } else {
    var manufacturer_id = $("#company_id").val();
    var rebate_no       = $('.well').length;
    var site_url        = $('#site_url').val();

    if ($('.well').length>=0) { 
      rebate_no = rebate_no+1;
    }
      $('.add_new_rebate').attr('disabled','disabled');
    }

    $.ajax({
      type: "POST",
      url: "add_rebate_by_product.php",
      data: {'request_type':'ajax', 'op':'create_rebate', 'rebate_no':rebate_no, 'manufacturer_id':manufacturer_id},  
      beforeSend: function() { 
        $('.load_img').html("<img src='"+site_url+"img/ajax-loader.gif' class='load' alt='Loading...'>");
      },
      success: function(data) {
        if(jQuery.trim(data)=="session_time_out") {
          window.location.href = site_url+'admin/login.php?timeout=1';              
        } else {
          $('.rbt').append(data);
          $('.add_new_rebate').removeAttr('disabled');

          //code for state select control to make functionality workable in newly added rebate block
          $('.states').multiselect({
            includeSelectAllOption: true,
            maxHeight: 150
          });
          //code for datepicker control to make functionality workable in newly added rebate block
          $(".date_control").datepicker({
            dateFormat: "yy-mm-dd"
          });                   
        }
        $('.load').remove();
      }
    });
//}
}
Run Code Online (Sandbox Code Playgroud)

现在有人可以解释以下文件的作用以及它的重要性吗?

if($.active > 0) { //or $.active        
        request_inprogress();
      }
Run Code Online (Sandbox Code Playgroud)

提前致谢.

Mal*_*ana 6

jQuery $.active是jQuery在内部使用但在官方文档中没有提到的函数.但是在我们编码时使用是没有问题的.

它是为ajaxStart()和启用全局事件处理程序的标志ajaxStop().您可以在此处找到更多详细信息并阅读问题.

以下是github上的一些代码片段.

1.

// Counter for holding the number of active queries
active: 0,
Run Code Online (Sandbox Code Playgroud)

2.

// Watch for a new set of requests
if ( fireGlobals && jQuery.active++ === 0 ) {
    jQuery.event.trigger("ajaxStart");
}
Run Code Online (Sandbox Code Playgroud)

3.

// Handle the global AJAX counter
if ( !( --jQuery.active ) ) {
    jQuery.event.trigger("ajaxStop");
}
Run Code Online (Sandbox Code Playgroud)