Skip to content

Instantly share code, notes, and snippets.

@robotlolita
Forked from anonymous/gist:979787
Created May 18, 2011 23:21
Show Gist options
  • Save robotlolita/979806 to your computer and use it in GitHub Desktop.
Save robotlolita/979806 to your computer and use it in GitHub Desktop.
// 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