使用jQuery autocomplete传递中文参数后台用request.getParameter("q");
取数据默认会是乱码,
可以在jquery.autocomplete.js 中大概第373行lastWord(term)进行编码 如下
$.ajax({
// try to leverage ajaxQueue plugin to abort previous requests
type:'post',
mode: "abort",
// limit abortion to this input
port: "autocomplete" + input.name,
dataType: options.dataType,
url: options.url,
data: $.extend({
q: encodeURI(lastWord(term)),
limit: options.max
}, extraParams),
success: function(data) {
var parsed = options.parse && options.parse(data) || parse(data);
cache.add(term, parsed);
success(term, parsed);
}
});
后台接收数据解码
q = URLDecoder.decode(q,"UTF-8");
取数据默认会是乱码,
可以在jquery.autocomplete.js 中大概第373行lastWord(term)进行编码 如下
$.ajax({
// try to leverage ajaxQueue plugin to abort previous requests
type:'post',
mode: "abort",
// limit abortion to this input
port: "autocomplete" + input.name,
dataType: options.dataType,
url: options.url,
data: $.extend({
q: encodeURI(lastWord(term)),
limit: options.max
}, extraParams),
success: function(data) {
var parsed = options.parse && options.parse(data) || parse(data);
cache.add(term, parsed);
success(term, parsed);
}
});
后台接收数据解码
q = URLDecoder.decode(q,"UTF-8");