-1
Hi... I have the following codes
HTML
<div class="escolha">
<h5>ESCOLHA A CIDADE</h5>
<select id="selectMunic" onchange="getMunic(this);">
</select>
<div class="Indice"><span>Indice:</span><strong>moradas</strong></div
</div>
Jquery and AJAX
Getting the cities to display in select, each city has its own Address Index, returned in JSON
<script>
var getMunics = function(){
$.ajax({
url: "/city.json", //apenas exemplo... passo a url completa aqui
method: "GET"
}).done(function( munics ) {
$(munics).each(function(){
$("#selectMunic").append("<option value='" + this.munic + "' >" + this.munic + "</option>");
})
});
}
Returning a specific city after selecting
var getMunic = function(select){
$.ajax({
url: "/city.json" + "?munic=" + select.value,
method: "GET"
}).done(function( munics ) {
if(munics.length > 0){
var munic = munics[0];
console.log(munic);
}
});
}
I checked on the console and is returning to the city and the address Index How do I display the Intel in HTML?
addresses - Naturally I know that so can’t rs
On the console I confirmed and returned as in the example below
{
id: 1,
munic: "Caxias do Sul",
moradas: 1000
}
I’m sorry if I’m a little confused, and my first question on Stackoverflow and also the lack of accents in the sentences.
Thank you