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

  • Home
  • SEARCH
  • 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 8367795
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T13:14:54+00:00 2026-06-09T13:14:54+00:00

I’m running a function to check if a database entry exists. On my page

  • 0

I’m running a function to check if a database entry exists.

On my page load I check if an element exists and if it does I use setInterval to run a function. Like so:

if ( $('#encoding').length ) {

    console.log("auto_update start");
    var update = setInterval(auto_update, 12000);
}

Then in my auto_update function this happens

function auto_update() {

    console.log("auto_update running");

    $.ajax({
        type: 'POST',
        url: ajaxurl,
        data: {
            action: "dhf_ajax_router",
            perform: "dhf_check_status", // the function we want to call
            post_id: $('#post_id').val(),
            nonce: $('#dhf-video-meta-nonce').val()
        },
        success: function(response) {

            if ( response === "continue" ) {

                console.log("still encoding");

            } else {

                clearInterval(update);
                console.log("complete " + response);
            }
        }
    });
}

The problem is if $('#encoding') wasn’t present on the page at the start and was fired by the user manually within:

$(document).on("click", ".run_encode", function(){

        // doing the necessary stuff here.
        if ( response === "sent" ) {

                // more stuff
                var update = setInterval(auto_update, 12000);
        } 

}); // end .run_encode

Then the clearInterval(update) doesn’t work, and it ends up in an endless loop.

I can’t figure out Why. An interval with the name update was set in both cases, so why does clearing it not work in the second situation?

  • 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-09T13:14:55+00:00Added an answer on June 9, 2026 at 1:14 pm

    You will have to make sure that the shared variable update is available in both scopes. This means that it either needs to be in a common parent scope or you need to make the update variable a global variable so it does not go out of scope.

    Most likely, you’re declaration of update is inside a function that terminates and when that function terminates, the update variable goes out of scope and is destroyed.

    You can make the initial setting of the variable go into the global scope (so it will still be available when you call clearInterval() like this:

    $(document).on("click", ".run_encode", function(){
    
        // doing the necessary stuff here.
        if ( response === "sent" ) {
    
                // more stuff
                window.update = setInterval(auto_update, 12000);
        } 
    
    }); // end .run_encode
    

    Or, you could just declare the update variable to be global, by first putting this at the global level (outside of any functions) and then this code would just modify the global variable:

    var update;
    
    $(document).on("click", ".run_encode", function(){
    
            // doing the necessary stuff here.
            if ( response === "sent" ) {
    
                    // more stuff
                    update = setInterval(auto_update, 12000);
            } 
    
    }); // end .run_encode
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I would like to run a str_replace or preg_replace which looks for certain words
I am currently running into a problem where an element is coming back from
I would like my Web page http://www.gmarks.org/math_in_e-mail.txt on my Apache 2.2.14 server to display
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I would like to count the length of a string with PHP. The string
For some reason, after submitting a string like this Jack’s Spindle from a text
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has

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.