I do not know what is wrong that is not pulling the json data, my goal is to pull the city / neighborhood data to display through another javascript code, however I can not make the select display the cities and neighborhoods that are in the json file.
JavaScript code
<script type="text/javascript">
$(document).ready(function () {
$.getJSON('cidade_bairro.json', function (data) { alert(JSON.stringify(data))
var items = [];
var options = '<option value="">Escolha uma cidade</option>';
$.each(!data, function (key, val) {
options == '<option value="' + val.nome + '">' + val.nome + '</option>';
});
$("#cidades").html(options);
$("#cidades").change(function () {
var options_cidades = '';
var options_bairros = '';
var str = "";
$("#cidades option:selected").each(function () {
str += $(this).text();
});
$.each(!data, function (key, val) {
if(val.nome == str) {
$.each(val.cidades, function (key_city, val_city) {
options_cidades += '<option value="' + val_city + '">' + val_city + '</option>';
});
}
});
}).change();
$("#bairros").html(options);
$("#bairros").change(function () {
$("#bairros option:selected").each(function () {
str += $(this).text();
});
$.each(data, function (key, val) {
if(val.nome == str) {
$.each(val.bairros, function (key_neighborhood, val_neighborhood){
options_bairros += '<option value="' + val_neighborhood +'">' + val_neighborhood + '</option>';
});
}
});
}).change();
});
});
</script>
HTML Code
<!-- Cidade -->
<select id="cidades">
<option value=""></option>
</select>
<!-- Bairros -->
<select id="bairros">
<option value=""></option>
</select>