我正在使用这个插件:http://jqueryui.com/demos/autocomplete/#remote
效果很好,但我想这样使用请求URL:"www.mysite.com/ search /my search input“,而不是这样:"www.mysite.com/?term=my search input”,因为我使用codeigniter,这就是我处理URL的方式。因此,我需要像这样添加搜索输入"/my搜索输入“,因为我可以给出网址的第一部分,但我不知道如何才能更改"?term=”的追加。
问题是URL将被附加上?term=value,这就是我需要更改为/search/value的内容。Codeigniter在这里不是问题,我相信自动补全代码需要更改。
有什么想法吗?
谢谢。
发布于 2010-10-06 07:45:36
我设法用下面的代码解决了这个问题:
$( "#test" ).autocomplete({
source: function(req, add){
$.ajax({
url: 'search/q',
dataType: 'json',
type: 'POST',
data: req,
success:function(data){
var items = [];
$.each(data, function(i, val){
items.push(val);
});
add(items);
}
})
},
minLength: 2,
autoFill:true,
highlight:true,
scroll:true,
selectFirst:true,
matchContains: true
});如果有人在寻找同样的东西,我希望它能派上用场。
发布于 2010-10-05 23:32:39
您可以直接在自动完成的URL参数中使用codeigniter URL。我在我的一个项目中使用了下面的一个。
<script>
$(document).ready(function(){
$("#search").autocomplete('<?php echo site_url('ajax/get_words');?>', {
extraParams: {
language: function() { return 'english'; }
}
});
});
</script>我希望这能对你有所帮助。如果你需要更多,请告诉我。
https://stackoverflow.com/questions/3865176
复制相似问题