如何禁用计时器? [重复]

This question already has answers here:
                </div>
            </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2013-02-04 05:21:46Z" class="relativetime">7 years ago</span>.</div>
        </div>
    </aside>

Possible Duplicate:
Stop setInterval call in javascript

I use window.setInterval method for polling progress status. But need to disable this timer when it completed. How to disable timer?

      window.setInterval(function(){$.ajax({
          type: 'GET',
          url: 'imports',
          success: function(response){
            console.log(response);
            if(response['status'] != 'ok'){
              return;
            }

            $('.bar').css('width', response['progress'] + '%');

            if(response['step'] == 'completed') location.reload();
      }}, 'json');}, 1000);
</div>

the setInterval() method will return an integer/number. You need to store this, then pass it to the method clearInterval() to stop it.

var intervalId = window.setInterval(.....);

then later, when you want to stop it, I think it would go:

window.clearInterval(intervalId);

setInterval() returns a handle which you can later pass to window.clearInterval() to stop the timer.

var x = window.setInterval(...);
// ...
window.clearInterval(x);

When you start the interval it returns an integer defining it:

var timer = window.setInterval( ... );

You can then clear that interval when your AJAX function returns true:

...
success: function(response) {
  console.log(response);
  if (response['status'] != 'ok') {
    clearInterval(timer);
    return;
  }
}
...