Skip to content

Instantly share code, notes, and snippets.

@dirkk0
Last active December 22, 2015 00:18
Show Gist options
  • Select an option

  • Save dirkk0/6387967 to your computer and use it in GitHub Desktop.

Select an option

Save dirkk0/6387967 to your computer and use it in GitHub Desktop.
Simple example to get JSON data
{
"users": [
"Jim",
"Jack",
"Joe"
]
}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<script src="http://code.jquery.com/jquery.min.js"></script>
</head>
<body>
<div id="content"></div>
<script>
$(document).ready(function() {
myData = {} ; // just to be able to introspect the data on the console (global var)
$.getJSON('list.json', function(data)
{
console.log(data);
myData = data; // dito
for(var i in data.users) {
item = data.users[i];
// $("#content").append(item)
$("<div/>", {
id: i,
text: item,
onClick: "console.log('you clicked "+item+"')"
}).appendTo("#content");
}
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment