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 6995303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:00:19+00:00 2026-05-27T20:00:19+00:00

The issue is best explained by the code: var myinterval = setInterval(function() { $.ajax({

  • 0

The issue is best explained by the code:

var myinterval = setInterval(function() {
    $.ajax({
        data: data
        url: url,
        success: function(data) {
            if (data) { /* I want to clear current interval */ }
            else { /* let it firing ajax requests further */ }
        }
    });
}, 1000);

So, what I want is to fire ajax requests each second to check if status of “something” changed. And if this something has changed properly, I want to stop checking on it. Basically, I’m asking how do I do it the best and most understood way.

What I did before is kind of ugly:

window.x = {
  'debug' : document.location.host.indexOf('.ru') != document.location.host.length - 3
  };
var setItem = function(i,v) {
  if (window.x['debug'] && typeof window.x[i] != 'undefined' && typeof console != 'undefined' && window.x[i] != v)
    console.log('Value of item ' + i + ' has changed from ' + window.x[i] + ' to ' + v)
  window.x[i] = v
};
var getItem = function(i) {
  if (window.x['debug'] && typeof window.x[i] == 'undefined' && typeof console != 'undefined')
    console.warn('Value of item ' + i + ' is undefined (maybe was not set?)')
  return window.x[i]
};

So, yea, I’ve occupied global x here (this is my temporary storage). Now I can set my interval var to x:

setItem('myinterval', myinterval);

inside success function I can get this interval:

getIntem('myinterval');

and stop it:

clearInterval(getItem('myinterval'));

But this is really ugly, isn’t it?
What is the best better way of doing that?

  • 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-05-27T20:00:20+00:00Added an answer on May 27, 2026 at 8:00 pm

    Just use clearInterval(myinterval):

    var myinterval = setInterval(function() {
        $.ajax({
            data: data
            url: url,
            success: function(data) {
                if (data) {
                    clearInterval(myinterval);
                }
            }
        });
    }, 1000);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What is the best way to issue a http get in VB.net? I want
I think the issue is explained best with an example. public class MyService {
The issue is best explained with pictures, but you can try it for yourself
Just curious what is the best practice for solving the following issue. I have
The question is probably not the best one to describe my issue but I
Could be a known issue, an issue with my code or an oversight on
The best way to explain this is with code: byte roominspiration = 0; query
I've a Gridview control using an ODS(ObjectDataSource) to fetch data. For the best performance
I'm using Hibernate and I have a process/best practices issue. For an example, lets
This isn't easy to explain, but I'll try my best. The issue has started

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.