Created
June 6, 2013 14:05
-
-
Save dodopok/5721754 to your computer and use it in GitHub Desktop.
JSON - PHP/JQUERY
This file contains hidden or 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
$.ajax({ | |
// url para o arquivo json.php | |
url : "json.php", | |
// dataType json | |
dataType : "json", | |
// função para de sucesso | |
success : function(data){ | |
// vamos gerar um html e guardar nesta variável | |
var html = ""; | |
// executo este laço para ecessar os itens do objeto javaScript | |
for($i=0; $i < data.length; $i++){ | |
// coloco o nome e sobre nome | |
html += "<strong>Nome:</strong> "+data[$i].nome +" "+ data[$i].sobreNome; | |
// coloco a cidade | |
html += " <strong>Cidade:</strong> "+data[$i].cidade | |
// e por ultimo dou uma quebra de linha | |
html += "<br />"; | |
}//fim do laço | |
//coloco a variável html na tela | |
$('body').html(html); | |
} | |
});//termina o ajax |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment