views:

27

answers:

1

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: simulate 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);
A: 

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.

Sanjay Ginde
Thanks for your help. I'll adopt your suggestion unless I find a more polished way (in Python, for example, you can achieve this in a more straight manner). I mean, without using the initialize() function
Raffaele