mardi 9 mai 2017

Stopping setInterval and executing the rest of the code

The code I'm currently working with is this:

$(document).ready(function() {
$.ajaxSetup({ cache: false });
var refreshID = setInterval(function() {

  $('#purple-title').load('dbcheck.php');
  if ($('#purple-title').html() != "PLEASE SCAN YOUR CARD") {
    $("#waiting-for-signal").animate({
        opacity: '0'
    }, 300);
    $("#purple-title").animate({
        opacity: '0'
    }, 300);
    setTimeout(function(){
      $("#waiting-for-signal").css("visibility", "hidden");
      $("#purple-title").html("Welcome!");
      $("#screen").prepend('<img id="checked" src="assets/check.gif"/>');
      $("#screen").prepend('<p id="purple-title" class="purple-title" style="margin:20px 0px 0px 0px;">WELCOME<br /><br /><strong>ALEN ŠIMUNIC</strong><br /><br />UID: 31.42.43.25</p>');
      $("#checked").css("opacity", "1");
    }, 300);
    $("#purple-title").animate({
        opacity: '1'
    }, 300);
    setTimeout(function(){
      $("#purple-title").animate({
          opacity: '0'
      }, 300);
      $("#checked").animate({
          opacity: '0'
      }, 300);
    }, 2200);
    setTimeout(function(){
      location.reload();
    }, 2500);
  }

}, 500);
});

So if the condition of $('#purple-title').html() != "PLEASE SCAN YOUR CARD" is met, I'd like to exit the interval and do what is inside of that if() function.

Thanks in advance, any help is greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire