Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8173651
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T22:14:25+00:00 2026-06-06T22:14:25+00:00

I have multiple ajax requests with javascript code as response, and I need to

  • 0

I have multiple ajax requests with javascript code as response, and I need to stop execution of previos javascript code once new code was loaded, I mean to stop intervals, functions, timeouts…

My Code :

$.get("/ucmd", params, function(data) {
  var $data = document.createElement("div");
  $data.innerHTML = data;
  var em = $data.getElementsByTagName("*");
  for(var i=0;i<em.length;i++)
  {
    if(em[i].tagName === "SCRIPT")
    {
     if($("#"+em[i].id)) document.body.removeChild($("#"+em[i].id));
     var script = document.createElement("script");
     script.id = em[i].id;
     script.language="javascript";
     script.type="text/javascript";
     script.innerHTML = em[i].innerHTML;
     document.body.appendChild(script);
    }
  }
});

Is it possible to make it to stop execution of previous code when new code is loaded?

P.S: I would like to use pure javascript code.

My Solution :

  window.$timeout = {};
  window.$interval = {};

  window.$setTimeout = window.setTimeout;
  window.$setInterval = window.setInterval;
  window.$clearTimeout = window.clearTimeout;
  window.$clearInterval = window.clearInterval;

  window.setTimeout = function(id, code, delay) {
    if(typeof $timeout[id] !== "undefined") clearTimeout(id);
    $timeout[id] = $setTimeout(code, delay);
  }; 

  window.clearTimeout = function(id) {
    $clearInterval($timeout[id]);
    delete $timeout[id];
  };

  window.setInterval = function(id, code, delay) {
    if(typeof $interval[id] !== "undefined") clearInterval(id);
    $interval[id] = $setInterval(code, delay);
  }; 

  window.clearTimeout = function(id) {
    $clearInterval($interval[id]);
    delete $interval[id];
  };
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T22:14:26+00:00Added an answer on June 6, 2026 at 10:14 pm

    To stop an existing call using timeout(), you can use:

    clearTimeout(t);
    

    You may be able to keep a global var to keep cou8nt of times you function is called and code the clearTimeout() around that…

    make your calls like:

    t = setTimeout("thing()",1000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an AJAX intensive application that requires sending multiple AJAX requests rapidly or
I have an app that sends multiple Ajax requests simultaneously. I was originally running
The problem. I have multiple tab, their content is loaded via ajax, so the
Working on an AJAX website (HTML,CSS,JavaScript, AJAX, PHP, MySQL). I have multiple javascript functions
I have an ajax call that fires multiple times but is called once. function
I have a jQuery AJAX call that I will need to do multiple times
I have a page with multiple DevExpress gridviews which are late-loaded via ajax. The
I have multiple instances of the following code. var start_time = new Date().getTime(); setTimeout(function
I'm executing multiple(3) ajax requests. How can I check whether all of them have
I have multiple ajax forms on page that cointain same elemets, I have jquery

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.