-
-
Save robotlolita/979806 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
// put inside a .js file, referenced on the page by the resource's URI | |
// Create a local variable to hold `jQuery', so you type less. | |
// Using $ is stupíd, since that symbol is (by ES5 specs) reserved for | |
// machine-generated code. | |
void function(j) { | |
function get_data() { | |
// use functions to abstract code sections | |
function get_item(i) { return data[i].high + '<br>' + ~~(Math.random() * 111) } | |
function update(idx) { return j('#high').html(get_item(idx)) } | |
function process(data){ return j.each(data, update) } | |
return j.getJSON('script.php', process) | |
} | |
get_data() | |
var auto_refresh = setInterval(get_data, 5000) | |
}(jQuery) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment