Skip to content

Instantly share code, notes, and snippets.

@Crystalh
Created April 18, 2012 10:23
Show Gist options
  • Save Crystalh/2412673 to your computer and use it in GitHub Desktop.
Save Crystalh/2412673 to your computer and use it in GitHub Desktop.
JSON loader replacement
function Jsonloader(options) {
var defaults = {
callbackInterval: 15000 //15 seconds
callbackString: "jsoncallback",
success = options.success || function() { },
url = options.url || ""
};
this.defaults = jQuery.extend(true, defaults, options || {})
}
//PUBLIC API METHODS AND PROPERTIES
Jsonloader.prototype.loadJson = function() {
var that = this;
return $.ajax({
url : this.url,
dataType : 'jsonp',
jsonpCallbackString : this.callbackString,
success : function(data) { that.success(data) }
});
}
Jsonloader.prototype.setCallbackInterval = function() {
//set callbackInterval prop on Jsonloader object
}
Jsonloader.prototype.createUpdateTimer = function() {
//create setTimeout, which calls loadJson() method
}
Jsonloader.prototype.stopPolling = function() {
//clear timeout
}
Jsonloader.prototype.startPolling = function() {
//call createUpdateTimer()
}
//PRIVATE METHODS AND PROPERTIES
function clearTimer(timer) {
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment