如何逐步使用自动完成功能 [英] how to use autocomplete step by step
本文介绍了如何逐步使用自动完成功能的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,希望您能给我一个有关如何使用jquery创建自动完成功能的想法或任何有效示例".我有一些示例,但无法正常使用
Hello guys hope you can give me an idea or any "Working Sample" on how to create an autocomplete using jquery.. i have some sample but its not working
$(function() {
$( "#city" ).autocomplete({
source: function( request, response ) {
$.ajax({
url: "http://ws.geonames.org/searchJSON",
dataType: "jsonp",
data: {
featureClass: "P",
style: "full",
maxRows: 12,
name_startsWith: request.term
},
success: function( data ) {
response( $.map( data.geonames, function( item ) {
return {
label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName,
value: item.id,
source: item
}
}));
}
});
},
minLength: 2,
change: function(event, ui) {
if (ui.item) {
$(''#your_hidden_input'').val(ui.item.source.id);
$(this).val(ui.item.value);
}
}
});
});
从这行开始
Based from this line
url: "http://ws.geonames.org/searchJSON",
当我键入它时,应该转到http://ws.geonames.org/searchJSON,但问题是当我键入我的值时,它会转到该URL
http://mysite.com/undefined?query=myqueryvalue"
非常感谢大家的帮助和想法.
when i type in it should go to http://ws.geonames.org/searchJSON but the problem is when i type in my value it goes to this url
http://mysite.com/undefined?query=myqueryvalue"
and help and idea is very much appreciated guys thanks in advance
推荐答案
(function(){
(function() {
("#city" ).autocomplete({ 来源:function(request,response){
( "#city" ).autocomplete({ source: function( request, response ) {
.ajax({ 网址:"http://ws.geonames.org/searchJSON", dataType:"jsonp", 数据: { featureClass:"P", 风格:丰满", maxRows:12 name_startsWith:request.term }, 成功:功能(数据){ 响应(
.ajax({ url: "http://ws.geonames.org/searchJSON", dataType: "jsonp", data: { featureClass: "P", style: "full", maxRows: 12, name_startsWith: request.term }, success: function( data ) { response(
这篇关于如何逐步使用自动完成功能的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文