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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T02:04:57+00:00 2026-06-17T02:04:57+00:00

I am doing some long polling (ajax) and I am looping the following portion

  • 0

I am doing some long polling (ajax) and I am looping the following portion of code.. There is code being executed above and below. This code is part of an internal messaging system. A certain portion of the page wil blink when a message arrives. If the user checks the message, it will remove the dash_notify from the JSON response, which needs to turn off the blinking. See below:

if (data.dash_notify == '1') {
    var x = '#dash_notif_blink';

    function blinking(x) {
        timer = setInterval(blink, 10);

        function blink() {
            x.fadeOut(400, function () {
                x.fadeIn(400);
            });
        }
    }

    console.log("initiate_dash");
    blinking($(x));
} else if (!data.dash_notify) {
    console.log("good");

    clearInterval(timer);
}

The following JSON response that gets sent to this code is:

{"current_date_time":"January 8, 2013 - 4:02 pm","dash_notify":"1"}

It understand the initial blink IF the above data gets passed. If the following gets passed:

{"current_date_time":"January 8, 2013 - 4:02 pm"}

Then it throws an error:

Uncaught ReferenceError: timer is not defined 

I cannot figure out how to fix the “else” portion working properly. If the code is initiated when the full dash_notify:1 response is sent, it works perfect. The button will blink, then if the user checks the message, it will no longer send dash_notify:1 and the button stops blinking. But if the code is initiated when dash_notify:1 is NOT set, it doesn’t know what to do with the ClearInterval.

Basically I need the else portion fixed.

I have tried using different typeOf === undefined snippets, but it doesn’t work.

Any help is appreciated.

Thank you!

EDIT:

This is currently working.. Timer is now defined above the statement

if(data.dash_notify == '1'){

                            var x = '#dash_notif_blink';

                        console.log("initiate_dash");
                        blinking($(x));

                        }else if (typeof timer != "undefined" && timer) { 
                            clearInterval(timer);
    }               
                    }

This is working, but sometimes it trys to kill the timer but it doesn’t actually do it. This happens every so often.

  • 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-17T02:04:58+00:00Added an answer on June 17, 2026 at 2:04 am

    This is now working beautifully.
    *Thank you to everyone who helped!*

    if(data.dash_notify === ‘1’ && t === null ){

                        var x = '#dash_notif_blink';
    
                        function blinking(x) {
                            var timer = setInterval(blink, 10); //note the var keyword for best practice
    
                            function blink() {
                                x.fadeOut(400, function () {
                                    x.fadeIn(400);
                                });
                            }
                            return timer;
                        }
    
                        console.log('initiate_dash_alert');
    
                        // Data is passed. Parse to see if dash alert should be called. Secondary protection for
                        // multiple timer creation.
                        if(t){return;}else{t = blinking($(x));}
    
    
    
    
                    }else if (!data.dash_notify){    
                        clearInterval(t);
                        console.log('clear_dash_alert');
                        t = null;
                    }else{
                        console.log(t);
                        console.log('no_push_events');
    
                    }                   
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

M using the following code for printing but if there are some long lines
I'm doing some kind of finding my device using this code: NSOperationQueue* quququ; int
I've been doing some practice for my O/SCJP exam. Consider the following code: public
I'm doing some experimenting with x86-64 assembly. Having compiled this dummy function: long myfunc(long
I have a very simple long polling ajax call like this: (function poll(){ $.ajax({
While doing some JavaScript performance tests I came up with the following piece of
Some long-gone developer left the following LINQ query behind with no documentation and I'm
I seem to be having a problem with long polling and IE. This is
I have previous experience doing a long polling with PHP and jQuery that check
I have a long running Content Provider, basically it is doing some searches in

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.