Skip to content

Instantly share code, notes, and snippets.

@sirleech
Created February 27, 2013 11:56
Show Gist options
  • Save sirleech/5047400 to your computer and use it in GitHub Desktop.
Save sirleech/5047400 to your computer and use it in GitHub Desktop.
Jquery AJAX call to JSON rest service, with spinner animation during load
<html>
<head>
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<style>
body {font-size: 200%;}
.hidden {display:none;}
</style>
</head>
<body>
Random: <div id="randomNumber">RAND</div>
Date: <div id="dateTime">DATE</div>
<div id="spinner" class="hidden"><img src="http://project.wnyc.org/elections/patchwork-vote-wi/images/spinner.gif"></div>
</body>
<script>
function refresh(){
$("#spinner").toggleClass("hidden");
$.getJSON("http://192.168.1.9/cgi-bin/hello.py", function(json) {
$("#spinner").toggleClass("hidden");
$("#randomNumber").html(json.randomNumber);
$("#dateTime").html(json.date);
console.log(json);
setTimeout(refresh,3000);
});
}
refresh();
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment