簡體   English   中英

jQuery UI自動完成-無法獲取在輸入字段中鍵入的數據

[英]JQuery UI AutoComplete - can't get data typed in the input field

我將Jquery UI自動完成的標准方法更改為使用POST而不是GET:

$(function () {
    var data = $(this).val();
    var dataString = 'location=' + data;

    $(".suggest_locations").autocomplete({

        source: function (request, response) {
            $.ajax({
                type: "POST",
                url: "ajax.php",
                data: dataString,
                dataType: "json",
                cache: false,
                success: response
            })
        },
        minLength: 1,
        delay: 0,
        autoFocus: true
    });
});

但是,無論我在輸入字段中寫什么,“數據”始終為空。

我正在使用一個名為ajax.php的外部文件來從數據庫獲取所有保存的位置,但是它將始終顯示所有可用的位置,因為“數據”不會讀取我在輸入字段中鍵入的內容。

我非常感謝您的幫助!

更改輸入字段的值時,變量數據不會更新,而只會更新一次:加載文檔時。

使用它代替源選項:

source: function(request, response) {
    $.ajax({
        url : 'ajax.php',
        type    : 'post',
        dataType: 'json',
        data    : 'location=' + request.term,
        cache   : false,
        success : function(data) {
            response(data);
        }
    });
}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM