Skip to content

Instantly share code, notes, and snippets.

@aghecht
Created January 27, 2012 01:48
Show Gist options
  • Save aghecht/1686417 to your computer and use it in GitHub Desktop.
Save aghecht/1686417 to your computer and use it in GitHub Desktop.
Demo of Asynchronous JavaScript Events
<html>
<head>
<title>Test Page</title>
</head>
<body>
<p id="paragraph1">This is a list of key-value pairs</p>
<p id="paragraph2"></p>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" ></script>
<script language="JavaScript">
console.log("Start of JavaScript")
$.getJSON('/data.json',
function(data) {
console.log(" AJAX Callback")
$.each(data, function(key, value) {
$('p#paragraph2').append(key + " has a value of " + value + "<br>");
})
})
console.log("Counter...");
for (var i = 0; i < 10; i++) {
console.log(" " + i);
}
console.log("End of JavaScript")
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment