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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T02:55:24+00:00 2026-06-03T02:55:24+00:00

I use the function below to check on the status of a JSON file.

  • 0

I use the function below to check on the status of a JSON file. It runs every 8 seconds (using setTimeout) to check if the file has changed. Once the JSON’s status becomes ‘success’ I no longer want to keep calling the function. Can someone please show me how to do this? I suspect it involves the use of clearTimeout, but I’m unsure how to implement this.

Cheers!

  $(function() {
    var checkBookStatus = function() {
       var job_id = "#{@job.job_id}";
       var msg = $('.msg');
       var msgBuilding = $('#msg-building');
       var msgQueuing = $('#msg-in-queue');
       var msgSuccessful = $('#msg-successful-build');
       var msgError = $('#msg-error'); 
       $.ajax({ 
         url: '/jobs/'+job_id+'/status.json',

           datatype: 'JSON',
           success:function(data){
             if (data.status == "failure")  {
               msg.hide();          
               msgError.show();
             }
             else if (data.status == "#{Job.queue}")  {
            msg.hide();          
            msgQueuing.show();
         }
             else if (data.status == "#{Job.building}")  {
            msg.hide();          
            msgBuilding.show();
         }             
         else if (data.status == "#{Job.failure}")  {
             msg.hide();          
             msgError.show();
         }
         else if (data.status == "#{Job.success}")  {
             msg.hide();          
             msgSuccessful.show();

              }                    
           },       
       }).always(function () {
            setTimeout(checkBookStatus, 8000);
      });
    };    
   checkBookStatus();    
  });
  • 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-03T02:55:25+00:00Added an answer on June 3, 2026 at 2:55 am

    Before your call of checkBookStatus() at the end, put another call: var interval = setInterval(checkBookStatus, 8000);. Then on success you can clearInterval(interval).

    Do not use setTimeout for iteration.

    A lot of answers are suggesting just to use clearTimeout() however, you are checking the status after the timeout has expired, there is no timeout to clear. You need to not call setTimeout() in your always() function rather than to clear anything. So you could re-inspect the status inside your always() function I suppose, but your data object isn’t in scope there. It would be preferable to just use setInterval() outside of your checkBookStatus() function.

    $(function() {
        var checkBookStatus = function() {
            var job_id = "#{@job.job_id}";
            var msg = $('.msg');
            var msgBuilding = $('#msg-building');
            var msgQueuing = $('#msg-in-queue');
            var msgSuccessful = $('#msg-successful-build');
            var msgError = $('#msg-error'); 
            $.ajax({ 
                url: '/jobs/'+job_id+'/status.json',
                datatype: 'JSON',
                success:function(data){
                    if (data.status == "failure")  {
                        msg.hide();          
                        msgError.show();
                    }
                    else if (data.status == "#{Job.queue}")  {
                        msg.hide();          
                        msgQueuing.show();
                    }
                    else if (data.status == "#{Job.building}")  {
                        msg.hide();          
                        msgBuilding.show();
                    }             
                    else if (data.status == "#{Job.failure}")  {
                        msg.hide();          
                        msgError.show();
                    }
                    else if (data.status == "#{Job.success}")  {
                        msg.hide();          
                        msgSuccessful.show();
                        clearInterval(interval);
                    }                    
                }       
            });
        };    
        var interval = setInterval(checkBookStatus, 8000);    
        checkBookStatus();
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use function below to check connection to WiFi hotspot point: public boolean IsWiFiConnected(){
I typically use the below function to return the root URL if I ever
I use a jquery load function to display weather information below a webcam. It
When I use jQuery event listener to handle message event, like below: $(window).on('message', function(e)
PHP5.1.6 has no json_encode(), so I wanted to use function found on json_encode documentation
I' ve made a in JavaScript function to check every 100 ms if a
Server side, I use below function (used as espressjs middleware) function objCreation(req, res, next){
I use this function below to process the array data I retrieve from my
I'm not sure which php function to use for this.. How can I check
I use Linq to Entities to retrieve my records from DB. The function below

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.