我想运行一个AJAX脚本,根据两个参数查询我的数据库。 这就是我的形式
<form id="search-box" action="search.php" method="post">
<input type="hidden" name="ie" value="UTF-8" />
<input type="text" id="username" name="username" size="31" placeholder="username ..." />
/
<input type="text" id="surname" name="surname" size="31" placeholder="surname..." />
<input type="submit" id="submit-button" name="sa" value="search" />
</form>
这是AJAX的java脚本:
<script type="text/javascript">
$(function() {
$("#surname").autocomplete({
source: "ajax-user.php",
minLength: 2,
});
});
</script>
这就是执行查询的php
<?php
require_once('connection.php');
try {
$conn = new readPDO("test");
}
catch(PDOException $e) {
echo $e->getMessage();
}
$return_arr = array();
if ($conn)
{
$ac_term = "%".$_GET['term']."%";
$ac_term2 = "%".$_GET['term2']."%";
$query = "
SELECT
surname
FROM
worker
WHERE
lower(username)
LIKE lower(:term)
AND
lower(surname)
LIKE lower(:term2)
";
$result = $conn->prepare($query);
$result->bindValue(":term",$ac_term);
$result->bindValue(":term2",$ac_term2);
$result->execute();
/* Retrieve and store in array the results of the query.*/
while ($row = $result->fetch(PDO::FETCH_ASSOC)) {
$row_array['value'] = $row['repoName'];
array_push($return_arr,$row_array);
}
}
/* Free connection resources. */
$conn = null;
/* Toss back results as json encoded array. */
echo json_encode($return_arr);
?>
所以我无法做的是传递$ ac_term2值。有什么建议吗?