2013-04-18 73 views
-1

我想获得一个AJAX示例工作,但我无法得到它的工作。即时通讯使用xampp。该代码只是似乎没有工作...有没有目录的问题顺便说一句,我确信......我检查一切......AJAX不在localhost上工作?

rates.html

<html> 

    <head> 
    <script> 
     function showUser(str) { 
     if (str == "") { 
      document.getElementById("txtHint").innerHTML = ""; 
      return; 
     } 
     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 & amp; & amp; xmlhttp.status == 200) { 
      document.getElementById("txtHint").innerHTML = xmlhttp.responseText; 
      } 
     } 
     xmlhttp.open("GET", "getuser.php?q=" + str, true); 
     xmlhttp.send(); 
     } 
    </script> 
    </head> 

    <body id="top"> 
    <br /> 
    <div class="wrapper col3" style="background-image: url(); opacity: 0.7;"> 
     <?php include("header.inc"); ?> 
    </div> 
    <br /><br /><br /> 
    <div class="wrapper col2"> 
     <?php include("menu.inc"); ?> 
    </div> 
    <br /><br /> 
    <div class="wrapper col5"> 
     <h1>Rates</h1> 

     <p>Please select an activity to view its rate at Casela. Rates available for both residents and non-residents.</p> 
     <form> 
     <select name="activity" onchange="showUser(this.value)"> 
      <option value="">Please select an actvity</option> 
      <option value="1">Big Cats (Lions)</option> 
      <option value="2">Big Cats (Tigers)</option> 
     </select> 
     </form> 
     <div id="txtHint" style="padding: 20px;"></div> 
    </div> 
    <br /><br /> 
    </body> 

</html> 

getuser.php

<?php 
$q = $_GET["q"]; 
$con = mysql_connect('localhost', 'root', 'password'); 
if (!$con) { 
    die('Could not connect: ' . mysql_error()); 
} 
mysql_select_db("rates", $con); 
$sql = "SELECT * FROM activities WHERE id = '" . $q . "'"; 
$result = mysql_query($sql); 
echo "<table border='1'> 
    <tr> 
    <th>Activity</th> 
    <th>Description</th> 
    <th>Duration</th> 
    <th>Restriction</th> 
    <th>Resident</th> 
    <th>Non-Resident</th> 
    </tr>"; 
while ($row = mysql_fetch_array($result)) { 
    echo "<tr>"; 
    echo "<td>" . $row['Activity'] . "</td>"; 
    echo "<td>" . $row['Decription'] . "</td>"; 
    echo "<td>" . $row['Duration'] . "</td>"; 
    echo "<td>" . $row['Restriction'] . "</td>"; 
    echo "<td>" . $row['Resident'] . "</td>"; 
    echo "<td>" . $row['NonResident'] . "</td>"; 
    echo "</tr>"; 
} 
echo "</table>"; 
mysql_close($con); 
?> 
+0

你的意思是不工作?它在做什么呢? – Paulpro

+0

阿贾克斯不工作..一张桌子应该已经产生...但没有任何反应... – user2228135

+0

**追踪你的错误** – Sebas

回答

5

这条线:

if (xmlhttp.readyState==4 &amp;&amp; xmlhttp.status==200) 

应该是这样的:

if (xmlhttp.readyState==4 && xmlhttp.status==200) 
+1

该死!我怎么能看不到......谢谢:) – user2228135

+2

不要担心....在我的团队中一直发生着;) – Hackerman

相关问题