Skip to content

Instantly share code, notes, and snippets.

@marlonbernardes
Created May 20, 2015 19:36
Show Gist options
  • Save marlonbernardes/38d3db0505a7eb46ea92 to your computer and use it in GitHub Desktop.
Save marlonbernardes/38d3db0505a7eb46ea92 to your computer and use it in GitHub Desktop.
modulo-04-dia-04-ajax
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="http://code.jquery.com/jquery-1.11.3.min.js"></script>
</head>
<body>
<h1>AJAX</h1>
<button id="btn" style="padding: 20px; background: red; color: #fff">BUSCAR</button>
<ul id="conteudo" style="background: yellow; padding: 50px; width: 100%">
</ul>
<script>
$(function(){
$('#btn').click(function(){
executaAjax();
})
})
function executaAjax(){
$.ajax({
url: 'http://datapoa.com.br/api/action/datastore_search?resource_id=1ac41c33-fcd5-4b42-890f-a7bad6216663&limit=5',
type: 'GET',
dataType: 'json'
}).done(function(resposta){
var resultados = resposta.result.records;
resultados.forEach(function(resultado){
$('#conteudo').append('<li>' + resultado.Name + '</li>')
});
console.log('done');
}).fail(function(){
}).always(function(){
console.log('always')
})
}
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment