我以前使用jQuery的自動完成功能與Zend的項目幾個月。以下是我寫出來源的方式,希望它有所幫助。
$("#unit_autocomplete").autocomplete({
source: function(request, response) {
$.ajax({
url: 'http://localhost/becasPropias/public/unit/autocomplete/format/json'+
'/type/'+type+'/term/'+request.term,
dataType: "json",
success: function(data) {
$("#unit_autocomplete").removeClass('ui-autocomplete-loading');
},
error: function(jqXHR, textStatus, errorThrown){
$("#unit_autocomplete").removeClass('ui-autocomplete-loading');
}
});
},
minLength:2,
select: function(event, selectedItem) {
toggle('hidden_unit', selectedItem['item']);
},
open: function() {
$(this).removeClass("ui-corner-all").addClass("ui-corner-top");
},
close: function() {
$(this).removeClass("ui-corner-top").addClass("ui-corner-all");
}
});
出的這整個代碼,這裏是您感興趣的部分:
source: function(request, response) {
$.ajax({
url: 'http://localhost/becasPropias/public/unit/autocomplete/format/json'+
'/type/'+type+'/term/'+request.term,
dataType: "json",
success: function(data) {
$("#unit_autocomplete").removeClass('ui-autocomplete-loading');
},
error: function(jqXHR, textStatus, errorThrown){
$("#unit_autocomplete").removeClass('ui-autocomplete-loading');
}
});
}
進出該代碼
url: 'http://localhost/becasPropias/public/unit/autocomplete/format/json'+
'/type/'+type+'/term/'+request.term,
正如你看到的,你可以把網址如你所需。這個代碼可以在我的git account中找到。