Skip to content

Instantly share code, notes, and snippets.

@arisetyo
Created November 8, 2012 06:46
Show Gist options
  • Save arisetyo/4037281 to your computer and use it in GitHub Desktop.
Save arisetyo/4037281 to your computer and use it in GitHub Desktop.
simple JSON retrieving and displaying with jQuery
$(document).ready(function(){
getMembers();
});
function getMembers() {
$('#list').html(" ");
$("#monitor").html("<span>loading...</span>");
$.ajax({
type: 'GET',
url: 'members.json',
dataType: "json",
success: function(data) {
var html = "<table width='100%'>";
html += "<tr><th>No</th><th>Full Name</th><th>Position</th></tr>";
$.each(data.members, function(entryIndex, entry) {
html += "<tr>";
html += "<td>"+ entry.no +"</td>";
html += "<td>"+ entry.fullname +"</td>";
html += "<td>"+ entry.position +"</td>";
html += "</tr>"
});
html += "</table>";
$('#list').append(html);
$("#monitor").html("&nbsp;");
}
});
}
{"members":[{"no":"1","fullname":"Kurt Cobain","position":"vocals, guitars"},{"no":"2","fullname":"Krist Novoselic","position":"bass"},{"no":"3","fullname":"Dave Grohl","position":"drums"}]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment