使用JQuery AutoComplete挣扎......可能是一个简单的错误,但我看不到它。
未捕获的TypeError:$(...)。autocomplete不是函数
是一直出现的错误消息。
在顶部声明的javascript文件是:
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<script type="text/javascript" src="http://code.jquery.com/ui/1.10.1/jquery-ui.min.js"></script>
<link rel="stylesheet" href="http://ajax.googleapis.com/ajax/libs/jqueryui/1.10.1/themes/base/minified/jquery-ui.min.css" type="text/css" />
HTML:
<p><label>Country:</label><input type='text' name='country' value='' class='auto'></p>
用法:
<script type="text/javascript">
$(function() {
//autocomplete
$(".auto").autocomplete({
source: "autocomplete.php",
minLength: 1
});
});
</script>
autocomplete.php
<?php
define('DB_SERVER', 'dummytext');
define('DB_USER', 'dummytext');
define('DB_PASSWORD', 'dummytext');
define('DB_NAME', 'dummytext');
if (isset($_GET['term'])){
$return_arr = array();
try {
$conn = new PDO("mysql:host=".DB_SERVER.";port=8889;dbname=".DB_NAME, DB_USER, DB_PASSWORD);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $conn->prepare('SELECT * FROM country WHERE name LIKE :term');
$stmt->execute(array('term' => '%'.$_GET['term'].'%'));
while($row = $stmt->fetch()) {
$return_arr[] = $row['name'];
}
} catch(PDOException $e) {
echo 'ERROR: ' . $e->getMessage();
}
/* Toss back results as json encoded array. */
echo json_encode($return_arr);
}
?>
对此的任何帮助将不胜感激!