On Feb 8, 2006, at 5:01 PM, [EMAIL PROTECTED] wrote:
Does anyone have an example of timing out an XMLHttpreques using
Mochikit?
I've got a server that just listens, but never responds and after like
5 seconds or so, I'd like my app to give up trying to get something
back from it.
something like this should work:
var cancelWithTimeout = function (deferred, timeout) {
var canceller = callLater(timeout, function () {
// cancel the deferred after timeout seconds
deferred.cancel();
});
return deferred.addCallback(function (res) {
// if the deferred fires successfully, cancel the timeout
canceller.cancel();
return res;
});
};
Used like this:
var d = cancelWithTimeout(10.0, loadJSONDoc(...));
-bob