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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T20:11:41+00:00 2026-05-11T20:11:41+00:00

I am working on a simple AJAX page. when the page loads, it should

  • 0

I am working on a simple AJAX page. when the page loads, it should take the result from the PHP page and display it in the text box. If the result is “1” (which it should be), then it should pop up an alert saying “Ready.”

Main page’s code (t1_wait.php):

<html><head><title>Waiting...</title></head><body>

<script type="text/javascript">
function update(id)
{
   var xmlhttp;
   if (window.XMLHttpRequest){
         // code for IE7+, Firefox, Chrome, Opera, Safari
         xmlhttp=new XMLHttpRequest();
   }else if (window.ActiveXObject){
      // code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
   }else{
      alert("Your browser does not support XMLHTTP!");
   }

   xmlhttp.onreadystatechange=function(){
      if(xmlhttp.readyState==4){
         if(xmlhttp.responseText=="1")
            alert("Ready!");
         }
         document.myForm.status.value=xmlhttp.responseText;
      }
   }

   var requesturl = "t1_checkMatch.php?id="+id;
   xmlhttp.open("GET",requesturl,true);
   xmlhttp.send(null);

   // delay for 1 sec
   var date = new Date();
   var curDate = null;
   do { curDate = new Date(); }
   while(curDate-date < 1000);

}

<?php
   echo "update(".$_GET['id'].");";
?>

</script>


<form name="myForm">
Status: <input type="text" name="status" />
</form>

</body></html>

The PHP page being called out to (t1_checkMatch.php) (all db info replaced with *****):

<?php
$db_user = "*****";
$db_pass = "*****";
$db_name = "*****";
mysql_connect(localhost,$db_user,$db_pass);
@mysql_select_db($db_name) or die("Unable to select database");

$match_id = $_GET['id'];

$match_info = mysql_query("SELECT * FROM ***** WHERE id=".$match_id);
if(mysql_result($match_info,0,"usr2")==-1){
   echo "1";
}else{
   echo "0";
}
?>

When I go to the t1_wait.php?id=16 (the main page passing id=16 via GET), it should send a request to t1_checkMatch.php?id=16, which returns (yes, I checked) 1. This should trigger an alert saying “Ready” and cause 1 to appear in the text box, but neither of these things happen. The text box is blank.

What’s wrong? Thanks!

  • 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-11T20:11:42+00:00Added an answer on May 11, 2026 at 8:11 pm

    Ok. I figured it out, but I don’t know what I did. I did have a typo, but that isn’t the problem. The PHP code is the same, here is the main page code:

    <html>
    <body>
    
    <script language="javascript" type="text/javascript">
    <!-- 
    //Browser Support Code
    function update(id){
        var ajaxRequest;  // The variable that makes Ajax possible!
    
        try{
            // Opera 8.0+, Firefox, Safari
            ajaxRequest = new XMLHttpRequest();
        } catch (e){
            // Internet Explorer Browsers
            try{
                ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
            } catch (e) {
                try{
                    ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
                } catch (e){
                    // Something went wrong
                    alert("Your browser broke!");
                    return false;
                }
            }
        }
        // Create a function that will receive data sent from the server
        ajaxRequest.onreadystatechange = function(){
            if(ajaxRequest.readyState == 4){
                if(ajaxRequest.responseText.indexOf("1")!=-1){
                   document.myForm.status.value = "Ready!";
                   window.location = "t1_game.php?id="+id;
                }else{
                   document.myForm.status.value = "Waiting..."
                   update(id);
                }
            }
        }
        ajaxRequest.open("GET", "t1_checkMatch.php?id="+id, true);
        ajaxRequest.send(null); 
    }
    
    <?php
    echo "update(".$_GET["id"].");"
    ?>
    
    //-->
    </script>
    
    
    
    <form name='myForm'>
    Status: <input type='text' name='status' />
    </form>
    </body>
    </html>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 260k
  • Answers 260k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You should take a flag parameter in database as per… May 13, 2026 at 11:21 am
  • Editorial Team
    Editorial Team added an answer <?php $font = "courier"; if(isset($_GET['font'])){ $font = $_GET['font']; } ?>… May 13, 2026 at 11:21 am
  • Editorial Team
    Editorial Team added an answer I ended up redirecting the URL and passed the keyword… May 13, 2026 at 11:21 am

Related Questions

Trying to avoid re-inventing the wheel here. I have a Google Web Toolkit page
What is a fast and efficient way to implement the server-side component for an
I am currently working on an advanced web application that contains a number of
I'm doing some maintenance coding on a webapp and I am getting a javascript

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.