>我正在尝试使用带有 PHP 源文件的 JQuery 自动完成功能,但是当我使用 FIREBUG 检查时,我看到输入字段发生了变化,页面只是重新查询自己而不是调用我的源 PHP 文件
代码段
$().ready(function() {
$("#item_name").autocomplete("./utilities.php?op=autocomplete", {
width: 260,
matchContains: true,
//mustMatch: true,
minChars: 2,
//multiple: true,
//highlight: false,
//multipleSeparator: ",",
selectFirst: false
});
});
PHP 源文件
if($op=='autocomplete'){
$dataset = array();
$item_name = $_REQUEST['item_name'];
if (!$item_name) return;
$sql = "select select concat(item_id,' - ',item_name) item from payment_items where item_name like '%$item_name%'";
//echo $sql;
$result = mysql_query($sql);
if($result){
for($i=0; $i<$numrows; $i++){
$row = mysql_fetch_array($result);
echo $row['item'];
}
}
}
实用程序文件是一个实用程序页面,因此需要定义一个$op参数来确定我想要实现的目标。
感谢您的帮助
尝试删除"."
$("#item_name").autocomplete("/utilities.php?op=autocomplete", {
那么它应该请求 PHP 页面而不是它自己。
$("#item_name").autocomplete("/utilities.php?op=autocomplete",
{
width: 260,
matchContains: true,
//mustMatch: true,
minChars: 2,
//multiple: true,
//highlight: false,
//multipleSeparator: ",",
selectFirst: false
}).result(function(event, data, formatted) {
// your built function call
myDefinedFunction(data);
// update with another result
$(this).val('your value');
})
如文档:http://docs.jquery.com/Plugins/Autocomplete/result#handler