有没有自动填充城市样本? [英] any autocomplete cities samples?

查看:89
本文介绍了有没有自动填充城市样本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好...我一直在寻找使用jquery列出所有可能城市的任何示例或任何代码...但是我找不到提供此解决方案的简单示例...我有此代码我只是复制到一个网站上

Hello guys... i''ve been looking for any samples or any code that will lists all the possible cities using jquery... but i cant find a simple sample that gives this solution... i have this code that i just copied on one site

$( "#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.name
							}
						}));
					}
				});
			},
			minLength: 2,
			select: function( event, ui ) {
				log( ui.item ?
					"Selected: " + ui.item.label :
					"Nothing selected, input was " + this.value);
			},
			open: function() {
				$( this ).removeClass( "ui-corner-all" ).addClass( "ui-corner-top" );
			},
			close: function() {
				$( this ).removeClass( "ui-corner-top" ).addClass( "ui-corner-all" );
			}
		});


但是当我尝试运行它时,出现一个错误,提示我


but when i try to run it, gives me an error saying

404 Not Found - http://mysite.com/_subfolder/undefined?query=p"



不能真正解决问题...任何人都可以给我答案我的问题...在此先感谢



cant really solve the problem... can anyone give me an answer to my problem please... thanks in advance

推荐答案

("#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 }, 成功:功能(数据){ 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){ 返回 { 标签:item.name +(item.adminName1?," + item.adminName1:")+," + item.countryName, 值:item.name } })); } }); }, minLength:2 选择:function(event,ui){ log(ui.item? 已选择:" + ui.item.label: 未选择任何内容,输入为" + this.value); }, 打开:function(){
.map( data.geonames, function( item ) { return { label: item.name + (item.adminName1 ? ", " + item.adminName1 : "") + ", " + item.countryName, value: item.name } })); } }); }, minLength: 2, select: function( event, ui ) { log( ui.item ? "Selected: " + ui.item.label : "Nothing selected, input was " + this.value); }, open: function() {


这篇关于有没有自动填充城市样本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆