Created
June 1, 2010 06:53
-
-
Save bradgessler/420657 to your computer and use it in GitHub Desktop.
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
$.extend({ | |
poller: function(originalOptions){ | |
$.extend({ | |
interval: 0 /* Use this if you want to setup a short poller */ | |
}, originalOptions); | |
var applyRepoll = function(callback){ | |
return function(){ | |
if(typeof callback === 'function'){ | |
callback.apply(originalOptions, arguments); | |
} | |
setTimeout(function(){ return $.poller(originalOptions); }, originalOptions.interval); | |
}; | |
}; | |
var extendedOptions = $.extend({}, originalOptions, { | |
async: true, /* If set to non-async, browser shows page as "Loading.."*/ | |
timeout: 30000, /* Timeout in ms */ | |
cache: false, | |
success: applyRepoll(originalOptions.success), | |
error: applyRepoll(originalOptions.error) | |
}); | |
return $.ajax(extendedOptions); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment