Created
February 27, 2013 11:56
-
-
Save sirleech/5047400 to your computer and use it in GitHub Desktop.
Jquery AJAX call to JSON rest service, with spinner animation during load
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
<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