English 中文(简体)
j Query - 履行超时职能
原标题:jQuery - Keeping an asynchronous function from running more than once simultaneously

我的职能是“改革”引发的,“改革”将儿童申请列入名单并显示他们。 把它定做是同步的,会妨碍这一点,但我知道,为了显示对 Chrome和IE的装载icon,它需要同步。 问题在于,如果你在执行职务时不止一次地花钱,就会给孩子多倍加负担。 我所担心的是,阻止这一职能在一段时间内运作不止一次,以防止儿童被装上不止一次。

提前感谢!

我的阿贾克斯呼吁(由于我不以冲突方式行事,我不敢花钱):

 var ul = "#ul_" + categoryId;
    var ifUlExists = jQuery(ul); 

    // Only if UL not already loaded
    if (ifUlExists.length == 0) {

        jQuery.ajax({
     type:  POST ,
     url:  /adminajax/add_kids ,
     data: { 
      categoryId: categoryId
     },
     beforeSend:function(){
      // Toggle +/- icon  
      jQuery(expandIcon).addClass("loading");
     },
     success:function(resp){
      var kids = resp;         
      // If there are kids returned by the query
      if (kids){
       var container = "#c_"+categoryId;       
         jQuery(kids).insertAfter(jQuery(container));
         jQuery(ul).slideDown("slow");
      }
     })};
    } else {
  jQuery(expandIcon).addClass("collapse");
  jQuery(ul).slideDown("slow");  
    }
最佳回答

它不会“同时”运行;一个更好的词将是“同时”的。 只是举一个旗号:

if (ifUlExists.length === 0 && !$( body ).data( loadingUl )) {
  $( body ).data( loadingUl , true);
  // the rest of your code
}

使用“人”要素数据只是这样做的一种冲积方法,但像这种方式一样,因为<条码>(机构)价格很高。 当然,你可以在任何地方保持旗帜。

问题回答

国旗是一种选择:

var running = false;

$(selector).mouseover(function() {
    if(!running) {
         running = true;
         callAsyncFunction();
    }
});

在Ajax请求的回击中,再设置running = 虚假

If you want to do that for several elements, you can use the data() function of that element as @Pointy describes in his answer.





相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签