我想使用以php文件为源的jquery autocomplete"函数"。我不明白为什么它不起作用。如果我使用在变量中输入的数据,一切都很好。希望有人能帮忙。提前感谢您的回复。干杯马克。
我的HTML:
<input id="moi" type="text"/>
我的JS:
$(function() {
$( "#moi" ).autocomplete({
source: "php/search_loc.php",
minLength: 2
});
});
我的PHP:
<?php
header('Content-Type: text/html; charset=utf-8');
require("../inc/connect.inc.php");
mysql_set_charset('utf8');
$result = mysql_query("SELECT * FROM search_loc");
$row=mysql_fetch_assoc($result);
while($row=mysql_fetch_assoc($result)){
echo $row['srl_loc'].'<br>';}
?>
您的PHP脚本应该返回JSON数据,
在Jquery UI中自动完成单据
The datasource is a server-side script which returns JSON data,
将其封装在json_encode()
函数中:
echo json_encode($row['srl_loc']).'<br />';