javascript - Retry when no response from website -


i use recursive function below, in order reopen website if httpstatus != 200:

retryopen = function(){      this.thenopen("http://www.mywebsite.com", function(response){         utils.dump(response.status);         var httpstatus = response.status;          if(httpstatus != 200){             this.echo("failed website, retry");             this.then(retryopen);         } else{             var thisnow = hello[variable];             this.evaluate(function(valueoptionselect){                 $('select#the_id').val(valueoptionselect);                 $('select#the_id').trigger('change');             },thisnow);         }     });         }    

the problem retryopen function not go far callback function(response){}. then, script freezes.

i wonder how 1 change function able recursively try open website again if there no response website (not error code 404 or something)? in other words, how rewrite retryopen function reruns when function not reach callback after amount of time?

i try this. please note untested code, should on correct path

retryopen = function(maxretry){     var count = 0;     function makecall(url)     {          this.thenopen(url, function(response){             utils.dump(response.status);                 });      }      function openit(){         makecall.call(this,"http://www.mywebsite.com");         this.waitfor(function check() {             var res = this.status(false);             return res.currenthttpstatus === 200;         }, function then() {              var thisnow = hello[variable];                 this.evaluate(function(valueoptionselect){                     $('select#the_id').val(valueoptionselect);                     $('select#the_id').trigger('change');                 },thisnow);         }, function timeout() { // step execute if check has failed             if(count < maxretry)             {                 openit.call(this);             }             count++         },          1000 //wait 1 sec         );     }  openit(); } 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -