Click here to Skip to main content
15,944,958 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
What's wrong with my code below? I can't abort ajax with it.

What I have tried:

var started = false;
      $(document).ready(function () {
      $('#start').click(function () {
      var count = $("#list").val();
      var line = count.split("\n");
      started = true;
      line.forEach(function(value, index) {
          setTimeout(
                  var ajaxCall = $.ajax({
                      url: url,
                      type: 'GET',
                      data: someData,
                      success: function(result) {
                          //some works here
                       }
                  });
                          $('#stop').click(function () {
                          ajaxCall.abort();   //abort Ajax
                          $('#check').attr('disabled', false);
                          $('#stop').attr('disabled', 'disabled');

                      })
              }, 2000 * index);
           });
      });
  });
Posted
Comments
Richard Deeming 14-Jul-22 3:42am    
REPOST
The answer hasn't changed since yesterday:
How to set a timeout on foreach in ajax?[^]

If you're just going to ignore every answer you're given, then what's the point in trying to help you?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900