I'd like to wrap Prototype Ajax.Request in order to simulate AJAX latency. I mean, using a closure and Prototype's delay() facility, but apparently there is something wrong with my code
/*
* Purpose: sim开发者_StackOverflow中文版ulate AJAX latency when developing on localhost
* What's wrong?
*/
Ajax.Request = (function(original) {
return function(url, options) {
return original.delay(1, url, options);
};
}) (Ajax.Request);
This worked for me (using prototype 1.6.1):
Ajax.Request.prototype._initialize = Ajax.Request.prototype.initialize;
Ajax.Request.prototype.initialize = function ($super, url, options) {
return this._initialize.bind(this).delay(2, $super, url, options);
};
I believe the method signature for Ajax.Request.prototype.initialize
is different in older version of prototype (i.e. without the $super parameter).
This will update it for all Ajax requests though.
精彩评论