javascript - SetInterval not repeating the function execution -


i have js structure this:

var intervalid;  function counterupdater(){     intervalid = setinterval(ajax_counter_upload(),10000);   } function ajax_counter_upload(){     $.ajax({         type: "post",         url: "plan/counter.php",         data: {tipo:'bp'},         success: function(data){             $("#spinner_msg").fadeto(200,0.1,                 function(){                     $(this).html(data);                     $(this).fadeto(900,1);                 });         }     }); } function ajax_submit(){     var submit_val=$("#stato").serialize();     dest="plan/new_bp1.php";     $.ajax({         type: "post",         url: dest,         data: submit_val,         success: function(data){              data1=data.split("|");             if(data1[0]=="successo"){                  $("#spnmsg").fadeto(200,0.1,                     function(){$(this).removeclass().addclass("spn_success").html(data1[1]).fadeto(900,1)});                 }else if(data1[0]=="errore"){                     $("#spnmsg").fadeto(200,0.1,                     function(){$(this).removeclass().addclass("spn_error").html(data1[1]).fadeto(900,1)});                   }         },         complete: function(){             clearinterval(intervalid);             settimeout(function(){ $('.container').load('plan/home.php');},2000);          }     });     settimeout(function(){counterupdater();},2000); } 

goal run counter_updater each 10 seconds when ajax_submit starts , stop when ajax_submit ends.

what run counter_updater once. doing wrong?

there's mistake in setinterval call: have parentheses after (intended) callback function name, means function called once , setinterval gets return value (nothing, in case).

simply remove parentheses:

intervalid = setinterval(ajax_counter_upload, 10000); //                                         ^^ 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -