Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@Uriel29
Created April 2, 2016 19:52
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Uriel29/666b1b38968675e5fafbca6c51efa86b to your computer and use it in GitHub Desktop.
Save Uriel29/666b1b38968675e5fafbca6c51efa86b to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>JSON Sample</title>
</head>
<body>
<select id="testes" >
<option>Guamiranga</option>
<option>Carama</option>
<option value=" " selected="selected">Todas</option>
</select>
<div id="resultado"></div>
<script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
<script>
$(document).ready(function(){
var cidade = " ";
var nome = " ";
$( "#testes" ).change(function () {
var str = "";
$( "select option:selected" ).each(function() {
str += $(this).val() + " ";
});
console.log(str);
cidade=str;
var url = "http://site.com/index.php/json?cidade="+cidade;
$.getJSON( url, function( data ) {
//console.log(data);
//var teste = (data[0]['cidade']);
//console.log(data[1]['cidade']);
$( "#resultado" ).empty();
for (var i = 0; i <data.length; i++) {
//console.log(data[i]['id']);
//console.log(data[i]['cidade']);
$( "#resultado" ).append('<li>' +data[i]['nome'] + ' é ' + data[i]['cidade'] +'</li> <img src="http://site.com/index.php'+data[i]['Imagem']+'">' );
}
//$( "#resultado" ).html( teste);
});
})
.change();
})
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment