所以我一直试图创建一个使用ajax的搜索栏来将结果获取到一个php页面然后运行一个SQL查询并显示结果,我现在已经看了一段时间并且从iv管理调试.. ajax函数有效,我相信?并在原始文件中运行相应的页面。但是我的文本输入没有加载到查询中.. 所以我的问题: 我错过了什么,你怎么告诉php页面如何处理通过ajax发送的输入。是否有一种简单的方法可以将它变成一个php变量,以便在被送回之前轻松处理?
<script>
//-----------------ajax code for search by text section----(booking.php)---------
function showHint(str) {
var xhttp;
if (str.length == 0) {
document.getElementById("membersContainer").innerHTML = "";
return;
}
xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
if (xhttp.readyState == 4 && xhttp.status == 200) {
document.getElementById("membersContainer").innerHTML = xhttp.responseText;
}
};
xhttp.open("GET", "booking/searchActivity.php?q="+str, true);
xhttp.send();
}
</script>
-------------------- booking.php上的HTML代码--------------------- --------
<form action="">
<td> <input type="text" name="activity" id="activity" onkeyup="showHint(this.value)"</td>
<td></td>
</form>
------------------- searchActivity.php ------------------------- -----
<?php
include '../Global/DBConnect.php';
$activity=$_GET['activity'];
$query= "select * from scotiaExcursions where description like '%$activity%'";
$result=mysqli_query($db,$query);
echo "<div align='center'>";
echo "<table width='600' border='1'>";
echo "<tr>";
echo "<td>Excursion ID</td>";
echo "<td>Description</td>";
echo "<td>Price</td>";
echo "<td>Places Free</td>";
echo "<td>Order Now</td>";
echo "</tr>";
while ($row = mysqli_fetch_assoc($result))
{
echo "<tr>";
echo "<td>".$row['excursionId']."</td>";
echo "<td>".$row['description']."</td>";
echo "<td>".$row['price']."</td>";
echo "<td>".$row['availablePlaces']."</td>";
?>
<td>
<form name="addCart" id="addCart" action="../cheakout.php" method="POST">
<input type="hidden" name="activityID" id="activityID" value="<?php echo $row['excursionId']; ?>"/>
<input type="hidden" name="price" id="price" value="<?php echo $row['price']; ?>"/>
<input type="hidden" name="title" id="title" value="<?php echo $row['description']; ?>" />
<select name="qty" id="qty">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
</select>
<input type="submit" name="submit" id="blueButton" value="Order"/>
</form>
</td>
<?php
echo "</tr>";
}
echo "</table>";
echo "</div>";
?>