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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:33:40+00:00 2026-06-15T03:33:40+00:00

I am writing code for JavaScript.In which I am trying to check the remote

  • 0

I am writing code for JavaScript.In which I am trying to check the remote asp.net page(aspx) connection using AJAX.But also I want to check the condition that, this call will continue for 2 Minute only and with 10 sec time intervals.
not that but like that logic I am thinking,
If flag=true
if seconds < 120
setInterval(“GetFeed()”, 2000);

can anybody please help me for that.

Here is my code of Connection check,

            var learnerUniqueID1;
        var flag='true';

        function fnCheckConnectivity(coursId) 
        {
            //here will the remote page url
            var url = 'http://<%=System.Web.HttpContext.Current.Request.UrlReferrer.Host+System.Web.HttpContext.Current.Request.ApplicationPath%>/TestConn.aspx'; 
            //alert(url);
            if (window.XMLHttpRequest) {
                learnerUniqueID1 = new XMLHttpRequest();
            }
            else if (window.ActiveXObject) {
                learnerUniqueID1 = new ActiveXObject("Microsoft.XMLHTTP");
            }
            else
            {
                alert("Your browser does not support XMLHTTP!");
            }
            learnerUniqueID1.open("POST", url, true);
            learnerUniqueID1.onreadystatechange = callbackZone;
            learnerUniqueID1.send(null);
        }

        function callbackZone() 
        {
            if (learnerUniqueID1.readyState == 4) 
            {
                if (learnerUniqueID1.status == 200) 
                {
                    //update the HTML DOM based on whether or not message is valid
                    parseMessageZone();
                }
                else
                {   
                    flag='false';                       
                    alert('We have detected a break in your web connection, \n please login again to continue with your session');
                }
            }
        }

        function parseMessageZone() 
        {
            var result = learnerUniqueID1.responseText;
        }        

        function makePayment(obj)
        {
            try
            {
                var Id = obj.attributes["rel"].value
                //alert(Id);
                var res=confirm('Want to Continue.');
                if(res == true)
                {
                    startRequest(Id);
                    //return true;
                }
                else
                {
                    return false;
                }
            }
            catch(Error)
            {

            }
        }

        function startRequest(Id)
        {
            var milliseconds = 10000;
            currentDate = new Date();
            // start request
            pollRequest(milliseconds, false, currentDate, 120000,Id);
        }

        function pollRequest(milliseconds, finshed, date, timeout,Id)
        {
            if((new Date()).getTime() > date.getTime()+timeout)
            {
                // 2-minute timeout passed
                return;
            }
            if(!finished){
                  setTimeout(function(){
                     if(//check backend to see if finished)     //which method will go here
                     {   
                        fnCheckConnectivity(coursId);
                         pollRequest(milliseconds, true, date, timeout,Id);
                     }
                     else{
                         pollRequest(milliseconds, false, date, timeout,Id)
                     }
                  }, milliseconds);
                  return;
            }
            // when code reaches here, request has finished

        }
  • 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-15T03:33:41+00:00Added an answer on June 15, 2026 at 3:33 am

    I’m not sure I understand correctly, but if you are trying to poll the status of a request you made every ten seconds, why not try something like this?

    function startRequest(){
        var milliseconds = 10000;
        currentDate = new Date();
        timeout = 120000;
        // start request
        pollRequest(milliseconds, false, currentDate, timeout);
    }
    
    function pollRequest(milliseconds, finshed, date, timeout){
    
        if((new Date()).getTime() > date.getTime()+timeout){
            // 2-minute timeout passed
            return;
        }
    
        if(!finished){
              setTimeout(function(){
                 if(//check backend to see if finished){
                     pollRequest(milliseconds, true, date, timeout);
                 }
                 else{
                     pollRequest(milliseconds, false, date, timeout)
                 }
              }, milliseconds);
              return;
        }
    
        // when code reaches here, request has finished
    }
    

    Please note this is a recursive function and browsers have a recursion limit. Also, regarding the 2 minute timeout, you can either set the timeout as an ajax prefilter or add a variable that is added on each recursion.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing some Javascript code and I'm trying to change the current page as
I have this javascript code which makes possible writing in a file { var
I'm thinking about writing some code in JavaScript which I can use in my
Writing a third-party javascript code which uses underscore.js and tries to avoid conflicts with
I'm writing a lot of code in javascript lately and I'm using Prototype.js to
I'm writing a userscript for a page which has this HTML code block.. <span
i am writing javascript code on nodepad++,i am at beginner level and write just
I'm writing some Javascript code that generates an XML document in the client (via
I'm writing a piece of code in JavaScript that is supposed to replace all
I'm writing a simple Javascript library that makes use of some WebGL code. I'd

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.