我從ajax獲取數據,但我想用jquery自動完成。如何使用jQuery的自動完成功能與Ajax?
我使用自動完成填寫文本框中的名稱。從AJAX
{
"id": "2",
"name": "Jenny Doe",
"phone": "",
"email": "[email protected]",
"password": null,
"registered": "2014-04-11 15:06:02",
"address": "",
"email_subscription": "0",
"email_verified": "0",
"reset_password": null,
"facebook_uid": null,
"title": "",
"phone2": "",
"gender": null,
"booking_date": "0000-00-00",
"birthday": "0000-00-00",
"nationality": "",
"passport": ""
},
數據我想告訴顧客的名字時,我在輸入框中單擊。 我想知道如何使用ajax和自動完成來解決這個問題。
jQuery代碼
$('.customer').on('click', '.customer_name', function(){
var name = $(this).val();
var customer_url = '/api/users?name_fulltext' + name;
console.log(customer_url);
$.getJSON(customer_url, function(data){
customer_cache[name]= [];
for (var j in data) {
//index the results by id
customer_cache[name][data[j]["name"]] = data[j];
var customer_name = customer_cache[name][data[j]["name"]];
}
});
$('.customer_name').autocomplete({
});
});