私はサンプルサイトから取得したコードを持っていますが、米国からの結果のみを返すように以下のコードを変更する方法を誰かに教えてもらえないかと思っていました.
これは私がこれまでに持っているコードです:
$(function() {
function log( message ) {
$( "<div>" ).text( message ).prependTo( "#log" );
$( "#log" ).scrollTop( 0 );
}
$( "#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" );
}
});
});
どうやら、次のように JSON をリクエストできます。
http://ws.geonames.org/searchJSON?name_startsWith=Chic&country=US
私の質問は、上記のコードを変更して「&country=US」をリクエストに含めるにはどうすればよいかということです。いくつか試してみましたが、リクエストが完全に壊れています。