从php源文件自动完成重新查询源页面而不是调用PHP源文件

时间:2012-05-14 14:02:21

标签: php jquery

我正在尝试使用带有PHP源文件的JQuery Autocomplete,但是当我查看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 SOURCE FILE

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'];
            }
            }

    }

实用程序文件是一个UTILITY PAGE,因此需要定义一个$ op参数来确定我想要实现的目标。

感谢您的帮助

2 个答案:

答案 0 :(得分:0)

尝试删除'。'

$("#item_name").autocomplete("/utilities.php?op=autocomplete", {

那么它应该是请求PHP页面而不是自己。

答案 1 :(得分:0)

$("#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

相关问题