Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
AJAX and JSON guide for beginners
<button type="button" onclick="getJSON()">Get the users</button>
<table id="users"></div>
function getJSON() {
var ajax_req = new XMLHttpRequest();'GET', '', true);
ajax_req.onload = function() {
//status 200 means everything is ok
if (this.status === 200) {
var json = JSON.parse(this.responseText);
var row = '';
for (i in json) {
row += '<tr><td>' + json[i].login +
'</td><td><img src="' +
json[i].avatar_url + '</td></tr>';
document.getElementById('users').innerHTML = row;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.