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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T23:42:15+00:00 2026-05-22T23:42:15+00:00

I run a JavaScript function that send a xmlHttpRequest to an .ashx (let’s name

  • 0

I run a JavaScript function that send a xmlHttpRequest to an .ashx (let’s name it send_req() that run on page load for first time). For onreadystatechange, I have a function that receive XML data and show it on the page (let’s name this one getanswer()).

I want to automatically update XML data on the page every 20 seconds. For that, I use setTimeout(send_req(),20000) in the end of writexml(), but it doesn’t update data on the page. I add an alert() at the **** line in the code. It shows on the page every one second!

And my code works fine if I use it without setTimeout.

Here is my code

var Population = "";
var Available_money = "";
var resource_timer;
var httpReq_resource;

function send_req() {
    if (window.ActiveXObject) {
        httpReq_resource = new ActiveXObject("Microsoft.XMLHTTP");
    }
    else if (window.XMLHttpRequest) {
        httpReq_resource = new XMLHttpRequest();
    }

    var sendStr = "user_id=1";
    if (httpReq_resource)
    {
        httpReq_resource.onreadystatechange = getanswer;
        httpReq_resource.open("POST", "Answer_Resource_change.ashx");
        httpReq_resource.send(sendStr);
    }
}

function getanswer() {
    var results = httpReq_resource.responseXML;
    if (httpReq_resource.readyState == 4) {
        if (httpReq_resource.status == 200) {
            try {
                var value;
                var values = results.getElementsByTagName("values");
                for (var i = 0; i < values.length; i++) {

                    value = values[i];
                    Population = value.getElementsByTagName("Population")[0].firstChild.nodeValue;
                    Available_money = value.getElementsByTagName("Available_money")[0].firstChild.nodeValue;
                    ... and some more like two line up
                }

                make_changes();
                **********************************
                resource_timer = setTimeout(send_req(), 20000);

            }
            catch (e) {
            }
        }
    }
}

function make_changes() {
    $("li span#l1").text(Available_money + '/' + Population);
    ...and some more like up line
}
  • 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-22T23:42:16+00:00Added an answer on May 22, 2026 at 11:42 pm

    This:

    resource_timer = setTimeout(send_req(), 20000);
    

    Should be:

    resource_timer = setTimeout(send_req, 20000);
    

    The first executes the result of send_req() after 20 seconds, the second executes send_req itself.

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

Sidebar

Related Questions

' i have a javascript function that im trying to trigger and run. here
I have a php function that's run when a build.php page is loaded and
I need to run a JavaScript function onLoad(), but only do it if the
I want to run a simple JavaScript function on a click without any redirection.
I want to run javascript/Python/Ruby inside my application. I have an application that creates
Part of our java application needs to run javascript that is written by non-developers.
Is there anyway to automatically run javascript:window.print() when the page finishes loading?
When a regular expression is run JavaScript, is the regex engine that evaluates the
I have a JavaScript function that contains a for loop that iterates so many
I'm developing a JavaScript application that's meant to be run either from a web

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.