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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T20:30:31+00:00 2026-05-16T20:30:31+00:00

On my website I use a long polling jquery ajax function. This ajax call

  • 0

On my website I use a long polling jquery ajax function. This ajax call in this function has a 50 seconds time-out and then runs again, waiting for changes on the server.

However, sometimes the long polling http connection stops. This happens for instance when the internet connection is down, or when the client pc is turn on after sleep or hibernate. The problem with this is that the “complete” callback doesnt occur yet, the $.ajax() function is still waiting for the timeout, while the http connection doesnt exist anymore.

How can check with jquery/javascript if the connection is still open?

This is my long poller script:

function longPoller() {

    $.ajax({
        type: "GET",
        url: '/longpolltest2.php', 
        dataType: 'json',
        async: true, 
        cache: false,
        timeout:50000, /* Timeout in ms */

        success: function(data){ 

            alert('success');
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){

            alert('error');
        },

        complete: function() { 

            alert('complete');
            longPoller(); // restart long poller request
            }

    });
}

@jAndy, I have updated the script, but I receive the following error:

Permission denied for http://domain.com to create wrapper for object of class UnnamedClass

function masterLongPollerDebugger() {

    xhr = $.ajax({
        type: "GET",
        url: '/longpolltest2.php', 
        dataType: 'json',
        async: true, 
        cache: false,
        timeout:50000, 

        success: function(data){ 

            alert('success');
        },
        error: function(XMLHttpRequest, textStatus, errorThrown){

            alert('error');
        },

        complete: function() { 

            alert('complete');
            masterLongPollerDebugger();
            }

    });
}


function ajaxRunning() {

    xhr._onreadystatechange = xhr.onreadystatechange;  // store a reference

    xhr.onreadystatechange = function() 
    {  // overwrite the handler
        xhr._onreadystatechange();   // call the original stored handler
        alert(xhr.readyState);
        if (xhr.readyState === 3) 
            alert('Interactive');
    };
}
  • 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-16T20:30:32+00:00Added an answer on May 16, 2026 at 8:30 pm

    You would need to check the XHR readyState 3 (interactive) mode.

    longpolltest2.php should send some kind of "ping data" to your client (with an interval of a 10 seconds for instance). Data which was received before the readyState 4 was fired is called interactive and the XMLHttpRequest will fire a onreadystatechange with the readyState set to 3.

    This has some restrictions. IE <8 does not support it, 8 supports it over the XDomainRequest object. Some other browser might need a “prelude” of data before they fire a readyState 3.

    Another thing worth to mention: jQuery currently does not support an interactive mode (most likely because its far beyond from beeing cross-browser compatible).

    Anyway, there is a little workaround that issue:

    var xhr = $.ajax(...);
    
    xhr._onreadystatechange = xhr.onreadystatechange;  // store a reference
    
    xhr.onreadystatechange = function() {  // overwrite the handler
        xhr._onreadystatechange();   // call the original stored handler
        if (xhr.readyState === 3) alert('Interactive');
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.