0

Hello I am getting my browser crashed everytime I use this while loop. I tried this also with strings. By this I mean to put in variable string and go inside the loop, after the post returns an agreed value, the value in the variable should be rewritten and the loop should end. But it causes the browser to crash.

var check = 1;
while (check < 2) {

inm = 'NOINM-'+Math.floor(100000 + Math.random() * 900000);
$.post('oneclickupdate.php', {function:'check_duplicity', inm:inm}, function(data){
  if (data === 'no')
    {
      $('#1').val(inm);
      check = check + 1;
    }
  else if(data === 'yes')
  {
      check = 1;    
  }
  });
}
Penguin9
  • 481
  • 13
  • 23
marhyno
  • 677
  • 1
  • 8
  • 20
  • 1
    Possibly a better dupe target: http://stackoverflow.com/questions/5066002/sending-one-ajax-request-at-a-time-from-a-loop – Quentin Jan 10 '17 at 14:54
  • the loop execution is not going to wait for post response to return and increment `check` and it will execute a lot more than twice – Suraj Rao Jan 10 '17 at 14:58

0 Answers0