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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:29:02+00:00 2026-05-25T15:29:02+00:00

The following is supposed to check a page for data (a simple integer) every

  • 0

The following is supposed to check a page for data (a simple integer) every 10 seconds. When the integer exists (data != null), then alert and stop the interval for good).

BUT
Instead it queues up alerts, every 10 seconds. And when the script finally does find the integer it’s looking for, a flood of alerts pops up… one for every ten seconds. If the script lasts 50 seconds, you’ll get 5 alerts all at once 50 seconds after the page loads.

What’s the problem? Shouldn’t the if (data != null) { prevent the alert from triggering at all… until there’s data? I’m at a loss. Plus, “data” never shows up in the alert.

var pinger;
$(document).ready(function() {
    var pinger = setInterval(function(){
        $.get("/ajax.php", function(data) {
            if (data != null) {     /** Shouldn't this line stop loops? **/
                alert("alert" + data);
                clearInterval(pinger);
            }
        });
    }, 10000);
});
  • 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-25T15:29:02+00:00Added an answer on May 25, 2026 at 3:29 pm

    /ajax.php takes more time than the delay at which setInterval() calls your function. So when it ends, setInterval() had actually called the function multiple times.

    Use setTimeout() instead of setInterval():

    $(document).ready(function() {
        setTimeout(function self(){
            $.get("/ajax.php", function(data) {
                if (data != null) {
                    alert("alert" + data);
                } else {
                    setTimeout(self, 10000);
                }
            });
        }, 10000);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am creating a SMS app the following code is supposed to: check if
So I have a method which is supposed to check if a table exists
folks, from the following code int a = mysql_query(conn,INSERT into data VALUES (NULL,'tes','aja')); how
i've the following code, it's supposed to check if a variable from a DataList
Suppose I have the following HTML: <form id=myform> <input type='checkbox' name='foo[]'/> Check 1<br/> <input
The following snippet is supposed to take the value of PROJECT (defined in the
The following snippets are both supposed to calculate sha-1 sum. But for the same
Supposed I have the following string: string str = <tag>text</tag>; And I would like
I have the following method that is supposed to be a generic Save to
Given the following code (it's supposed to write helloworld in a helloworld file, and

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.