我有一个使用php进行查询和ajax的自动完成功能,它的工作来自localhost但是当我上传到网络时,它不会工作,这是我的代码。谢谢
<script type="text/javascript">
$(function() {
//autocomplete
$(".auto").autocomplete({
source: "search.php",
minLength: 1
});
});
$(function() {
//autocomplete
$(".auto1").autocomplete({
source: "search1.php",
minLength: 1
});
});
$(function() {
//autocomplete
$(".auto2").autocomplete({
source: "search2.php",
minLength: 1
});
});
</script>
这是我在数据库中的查询
<?php
define('DB_SERVER', 'localhost');
define('DB_USER', 'root');
define('DB_PASSWORD', '');
define('DB_NAME', 'jobs');
if (isset($_GET['term'])){
$return_arr = array();
try {
$conn = new PDO("mysql:host=".DB_SERVER.";dbname=".DB_NAME, DB_USER, DB_PASSWORD);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare('SELECT employee_name FROM employer WHERE employee_name LIKE :term');
$stmt->execute(array('term' => '%'.$_GET['term'].'%'));
while($row = $stmt->fetch()) {
$return_arr[] = $row['employee_name'];
}
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
/* Toss back results as json encoded array. */
echo json_encode($return_arr);
}
?>
感谢您的帮助