Created
April 2, 2016 19:52
-
-
Save Uriel29/666b1b38968675e5fafbca6c51efa86b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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