ajax响应页面没有响应

时间:2013-12-28 04:52:56

标签: javascript php ajax

我有一个使用AJAX的PHP程序,但由于某种原因,更新页面(响应文本)没有响应。我似乎无法找到什么错误,任何帮助将不胜感激。

程序只是进入数据库并从字段中获取日期,并使用AJAX将其发送到负责响应文本的更新页面。然后,更新页面只会获取发送日期,获取当前值并将其返回到原始页面,然后在警报框中显示这两个日期。

ajax_test.php:

 <html>
 <head>
 <script>
      var tmr;// timer
      var xmlhttp;

      function UpdateTable()
      { 
           if (window.XMLHttpRequest)
           {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlhttp=new XMLHttpRequest();
           }
           else
           {// code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
           }

      xmlhttp.onreadystatechange=function()
      {
           if (xmlhttp.readyState==4 && xmlhttp.status==200)
           {
                var tokens = xmlhttp.responseText.split("|");
                alert(tokens[0]+",    "+tokens[1]);
           }
      }

      xmlhttp.open("GET","update_ajax_test.php?date1="+newDate,true);
      xmlhttp.send();   
 }
 </script>
 </head>
 <body onload="tmr=setInterval(UpdateTable,5000)">
 <?php
      mysql_connect("xxxxxxxxxxx", "xxxxxxxxx", "xxxxxxxx") or die("not logged in");
      //////now selecting our database
      mysql_select_db("xxxxxxxxx") or die(mysql_error());

      $res = mysql_query("SELECT num FROM table1");
      $numEnter=$_GET['name'];

      echo'<form method="get" action="ajax_test.php">';
      echo'  <input type="text" name="name"><br>';
      echo' <input type="submit" name="submit" value="Submit Form"><br>';
      echo'</form>';

      date_default_timezone_set('America/New_York');
      $date = date('Y-m-d H:i:s');
      echo $date;

      mysql_query("INSERT INTO table1(num,last_updated) VALUES ('$numEnter','$date')");

      echo"<table border=1 id='t1'>";
      while ($row = mysql_fetch_array($res))
      {
           echo"<tr><td>";
           echo $row['num'];
           echo"</td></tr>";
      }
      echo"</table>";
 ?>
 <script>
      var newDate ;
      newDate=<? echo $date; ?>;
 </script>
 </body>
 </html>

update_ajax_test.php

 <?php
 //////connecting to our sql server
 mysql_connect("xxxxxxxxxxxxx", "xxxxxxxxxxx", "xxxxxxxxxx") or die("not logged in");
 //////now selecting our database
 mysql_select_db("xxxxxxxxx") or die(mysql_error());

 $former_page_date=$_GET['date1'];
 $query3=mysql_query("SELECT last_updated FROM table1 ORDER BY id DESC LIMIT 1");

 while($row=mysql_fetch_array($query3)){
      $update_page_date=$row['last_updated'];
 }////END WHILE

 echo $update_page_date;
 echo "|";
 echo $former_page_date;
 ?>

0 个答案:

没有答案