javascript - timer is not triggering after one minute using jquery or give some other solution to trigger function after every 1 min? -


 var settimer;  var istimeset = false;   if (!istimeset) {     settimer = $('#hdn_timertime').val();     istimeset = true;    }    initialtimer(); function initialtimer() {             var customminutes = 60 * parseint(settimer),          display = $('#time');      starttimer(customminutes, display); }  function starttimer(duration, display) {      var timer = duration, minutes, seconds;     setinterval(function () {          minutes = parseint(timer / 60, 10)         seconds = parseint(timer % 60, 10);          minutes = minutes < 10 ? "0" + minutes : minutes;         seconds = seconds < 10 ? "0" + seconds : seconds;          display.text(minutes + ":" + seconds);          if (--timer < 0) {              timer = duration;             $('#outputmeters').val(json.stringify(listitem));             // _hardmeter.updatemeterdata();             _hardmeter.tempupdatemeterdataconfirmation();          }     }, 1000); } 

this code using first time work fine after time start reducing , function fire quickly. don't know how happening. please me out in , if u have better solution .could u please share it??

you can use setinterval call same function repeatedly @ set intervals until either page unloaded or call clearinterval:

var timedfunction = function() {   ... // }  setinterval(timedfunction, 60 * 1000); 

if timed function takes arguments change each time, use settimeout , call within function body well

var timedfunctionwitharguments = function(iterations) {    console.debug(iterations); //    settimeout(timedfunctionwitharguments, 60 * 1000, iterations++); }  timedfunctionwitharguments(0); 

Comments

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -