callback decoration

1 view
Skip to first unread message

Sergio Fernández

unread,
Dec 15, 2009, 9:45:12 AM12/15/09
to Prototype & script.aculo.us
In a experiment, I'm trying to decorate the callbacks, but I didn't
find the way to make the bind...

What I'd like to do is to firstly get the control over response's
callback, do some common stuff, and then invoke the callback set by
the user.

Anyone has any idea how can I do something like that?

Thanks in advance.

Best

Sergio Fernández

unread,
Dec 15, 2009, 2:38:22 PM12/15/09
to Prototype & script.aculo.us
Using Ajax.Request(), I forgot to say it, sorry.

Eric

unread,
Dec 17, 2009, 12:25:56 PM12/17/09
to Prototype & script.aculo.us
Hi Sergio,

I am not sure what you mean by "make the bind" but here is an example
doing what you ask using ajax responders:

Ajax.Responders.register({
onCreate: function(ar)
{
ar.options.onSuccess = ar.options.onSuccess ||
Prototype.emptyFunction;

ar.options.onSuccess = ar.options.onSuccess.wrap(function
(localCB,xhr,xjs)
{
// Do your stuffs here
alert("Apex inboud!");

// Then call the provided callback
localCB(xhr,xjs);
});
}
});

new Ajax.Request('http://jsbin.com/azeyo',{
onSuccess: function(xr) { alert("CB:"+xr.responseText); }
});


You can see it working here: http://jsbin.com/afudi and play with the
code here: http://jsbin.com/afudi/edit

Eric

Reply all
Reply to author
Forward
0 new messages