var url="getuser.php"; 
url=url+"?q="+str  ;
url=url+"&sid="+Math.random() ;
xmlHttp.open("GET",url,true);
<?php
$q=$_GET["q"];
$con = mysql_connect('localhost', 'root', 'root');
if (!$con) { die('Could not connect: ' . mysql_error()); }
mysql_select_db("ajax_demo", $con);$sql="SELECT * FROM user WHERE id = '".$q."'";$result = mysql_query($sql);
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
<th>Age</th>
<th>Hometown</th>
<th>Job</th>
</tr>";
while($row = mysql_fetch_array($result))
{  echo "<tr>";
 echo "<td>" . $row['FirstName'] . "</td>"; 
 echo "<td>" . $row['LastName'] . "</td>"; 
 echo "<td>" . $row['Age'] . "</td>"; 
 echo "<td>" . $row['HomeTown'] . "</td>";
  echo "<td>" . $row['Job'] . "</td>"; 
  echo "</tr>"; 
 }
 echo "</table>";
 mysql_close($con);
?>
不起作用啊?

解决方案 »

  1.   

    返回的结果要在xmlHttp的回调函数里处理
      

  2.   

    你打开这个页面看看有没有这个内容啊。
    var url="getuser.php?q="+str+"&sid="+Math.random() ;
    xmlHttp.open("GET",url,true); 
    window.open(url);
      

  3.   

    不起作用啊?
    *------------------不起作用指什么?
    php取值没错, 你试下echo $_GET['q']; 看有没值, 大多是你客户端没提交到值