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

  • Home
  • SEARCH
  • 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 8347943
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T07:32:13+00:00 2026-06-09T07:32:13+00:00

I am trying to make a simple AJAX program, that always displays the newest

  • 0

I am trying to make a simple AJAX program, that always displays the newest text from a file.
It should be retrieving it from the file, wait 2 seconds, and if something changed, write it out.
I tried already but the code doesn’t seem to work.

<html>
<head>
    <script type="text/javascript">
        function sleep()
        {
            var dt = new Date();
            dt.setTime(dt.getTime() + 2000);
            while (new Date().getTime() < dt.getTime());
        }
        function loadXMLDoc()
        {
        var xmlhttp;
        if (window.XMLHttpRequest)
          {
          xmlhttp=new XMLHttpRequest();
          }
        xmlhttp.onreadystatechange=function()
          {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
            document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
            }
          }
        xmlhttp.open("GET","ajaxtest.txt",true);
        xmlhttp.send();
        }
    </script>
</head>
<body>
    <script>
    while (0=0)
     {
        loadXMLDoc();

    </script>
        <div id="myDiv"><h2>Status</h2></div>
        <script type="text/javascript">
        setTimeout(loadXMLDoc(),1000)
    }
    </script>

</body>
</html>

How do I get it to check and update the text automatically?

Thanks!

Edit:

Here is the final code for anybody who is interested:

<html>
<head>
    <script type="text/javascript">
        function loadXMLDoc()
        {
        var xmlhttp;
        if (window.XMLHttpRequest)
          {
          xmlhttp=new XMLHttpRequest();
          }
        xmlhttp.onreadystatechange=function()
          {
          if (xmlhttp.readyState==4 && xmlhttp.status==200)
            {
            document.getElementById("myDiv").innerHTML=xmlhttp.responseText;
            }
          }
        xmlhttp.open("GET","status.txt",true);
        xmlhttp.send();
        }
    </script>
</head>
<body>
    <script type="text/javascript">
        loadXMLDoc();
    </script>
    <div id="myDiv">Current Status</div>
    <script type="text/javascript">
        setInterval("loadXMLDoc()", 2000);
    </script>
</body>
</html>
  • 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-09T07:32:15+00:00Added an answer on June 9, 2026 at 7:32 am

    I am not sure if its a typo or a thing from another language. (Like PHP)

    In HTML you cannot have javascript code that goes across multiple script tags.

    Also your while loop has only one = sign, would need two to be comparison.

    But that being said you do want setTimeout or setInterval, because non multi-threaded javascript will just lockup, mulit-threaded ones would wasting processing time as well but not totally lockedup.

    Something like

    setInterval("loadXMLDoc()", 2000);
    

    setTimeout executes the first parameter as javascript after the second parameter of milliseconds.

    setInterval executes the like setTimeout except every X milliseconds.

    Both setTimeout and setInterval return a value which can be used to stop the javascript from being executed again.

    That value is used in clearTimeout(value) or clearInterval(value)

    The body of your page would look like this:

    <body>
        <div id="myDiv"><h2>Status</h2></div>
        <script type="text/javascript">
            setInterval("loadXMLDoc()", 2000);
        </script>
    </body>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to make a simple strict HTML file that includes jquery: <?xml version=1.0
I am trying to something simple -- make a jQuery script that will wait
I'm trying to make simple website with content background combined from 3 images: top
Trying to make a simple program to catalogue books. Something like this, for example:
Trying to make a simple program to catalogue books. Something like this, for example:
im trying to make a simple search on my database from the index action
I am trying to make a simple AJAX calling in PHP and have a
I have a very simple problem. I'm trying to make an ajax call using
Trying to make a call and retrieve a very simple, one line, JSON file.
I'm trying to make a little dynamic quote rotator that overlays text on an

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.