我的自动完成功能是:
$(document).ready(function(){
var a = $('#issued_to').autocomplete(
{
serviceUrl: 'http://myhost.com/ecard_emp_suggestion/',
minChars: 1,
delimiter: /(,|;)\s*/, // regex or character
maxHeight: 400,
width: 300,
zIndex: 9999,
deferRequestBy: 0, //miliseconds
//params: { country:'Yes' }, //aditional parameters
noCache: false, //default is false, set to true to disable caching
// callback function:
onSelect: function(value, data){ alert('You selected: ' + value + ', ' + data); },
// local autosugest options:
//lookup: ['January', 'February', 'March', 'April', 'May'] //local lookup values
});
});
现在的问题是,它发送请求到: http://myhost.com/ecard_emp_suggestion?query=input_text
但我需要http://myhost.com/ecard_emp_suggestion/input_text
什么&我应该在哪里改变??
答案 0 :(得分:1)
简而言之,你不应该这样做,主要是因为逃避问题。大多数后端无法使用http://myhost/com/card_emp_suggestion/space included
等网段中的随机字符串。
您应该查看允许回调源代码的jquery ui project's autocomplete,并且可以以任何您想要的方式实现后端调用。
答案 1 :(得分:0)
您必须使用自定义函数覆盖函数getSuggestions,因此在ready函数中初始化自动完成后,添加以下代码:
a.getSuggestions = function(q) {
var cr, me;
cr = this.isLocal ? this.getSuggestionsLocal(q) : this.cachedResponse[q];
if (cr && $.isArray(cr.suggestions)) {
this.suggestions = cr.suggestions;
this.data = cr.data;
this.suggest();
} else if (!this.isBadQuery(q)) {
me = this;
//me.options.params.query = q;
//$.get(this.serviceUrl, me.options.params, function(txt) { me.processResponse(txt); }, 'text');
$.get(this.serviceUrl + '/' + q, null, function(txt) { me.processResponse(txt); }, 'text');
}
}