私は基本的に、想定されるユーザーが何かを書き、jQuery が提案のリストを返し、ユーザーが 1 つを選択する一般的なオートコンプリート検索バーを構築しています。
私のAJAX 呼び出しは次のようになります。
var response = '';
var request = $.ajax({
url: "./includes/search_products.php",
type: "post",
dataType: "json",
data: serializedData,
success : function(text) {
response = text; // Gets the list of suggestions
}
});
応答は次のとおりです。
{"id":"2",
"companyId":"15",
"productTypeId":"1",
"label":"Alfa Romeo 159",
"price":"50000","comments":
"Random comment."}
.autocomplete の設定方法:
request.done(function (){
console.log("Works.");
$('#product_search').autocomplete({
source: response,
minLength: 1,
select: function(event, ui) {
alert("yey");
}
});
});
私が得るエラーメッセージは次のとおりです。
TypeError: this.source is not a function
PHP json_encode() のドキュメントに記載されている内容に基づいて、通常の応答では引用符を少なくする必要があると思います。
どうしたの?:(