I’m developing an API that will return JSON, but the API call have two parameters, “term” and “country”:
http://127.0.0.1:8000/internalapi/cidades/?country=PT&term=Barreir
How can I modify this call to support the extra API parameter “country”?
<script>
$(function() {
function log( message ) {
$( "<div>" ).text( message ).prependTo( "#log" );
$( "#log" ).scrollTop( 0 );
}
$( "#city" ).autocomplete({
source: function( request, response ) {
$.ajax({
url: "http://127.0.0.1:8000/internalapi/cidades/",
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" );
}
});
});
</script>
Any clues?
Best regards,
Update 1:
The HTML for choosing the country:
<div class="fieldWrapper">
<label for="id_country">País:</label>
<select id="id_country" name="country">
<option selected="selected" value="">(Nothing)</option>
<option value="PT">Portugal</option>
<option value="ES">Espanha</option>
</select>
</div>
You should add the parameter into the data object: