Created
November 8, 2012 06:46
-
-
Save arisetyo/4037281 to your computer and use it in GitHub Desktop.
simple JSON retrieving and displaying with jQuery
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
$(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(" "); | |
} | |
}); | |
} |
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
{"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