hi all,
i'd like to know if there's a way to send parameters to a callback in
Prototype. For example, i have a code like:
function getRSS() {
var url = "feed.xhtml";
var myAjax = new Ajax.Request( url, {method: 'get', parameters:
parms, onComplete: processRSS} );
}
function processRSS(xmlHttpRequest, responseHeader) {
var xmlString = xmlHttpRequest.responseText;
alert (xmlString);
}
would be possible to give more parameters to processRSS() and do
something like...
function processRSS(xmlHttpRequest, responseHeader, foo) {
var xmlString = xmlHttpRequest.responseText;
if (foo){
alert (xmlString);
}
}
thanks in advance for your help,
Luis
on 2008-06-26 20:13
on 2008-06-26 21:10
Something like this...
var myAjax = new Ajax.Request( url, {method: 'get', parameters:
parms, onComplete: processRSS.curry(foo)} );
I used to do this all the time in my classes with Function#bind but
since 1.6 they have introduced curry(We cooking rice?) which is a slim
downed version of bind specifically targeted to your use case. enjoy!
As a side note, things may not be as you first expect, the curried
parameter is going to come through first you'll be looking at a
signature more like this...
function processRSS(foo, xmlHttpRequest, responseHeader ) {
Techy demo, gotta look at the source and firebug console to see whats
happenin, http://positionabsolute.net/projects/javascript/CurryTest/
--
Matt Foster
Ajax Engineer
Nth Penguin, LLC
http://www.nthpenguin.com
on 2008-06-26 21:20
function getRSS(*memo*) {
var url = "feed.xhtml";
var myAjax = new Ajax.Request(url, {
method: 'get',
parameters: parms,
onComplete: function(res, headers) {
processRSS(res, headers, *memo*);
});
}
function processRSS(res, header, *memo*) {
...
}
getRSS(*myMemo*);
-Fred
On Thu, Jun 26, 2008 at 1:02 PM, ljundie <ljundie@gmail.com> wrote:
> var url = "feed.xhtml";
> }
> alert (xmlString);
> }
> }
>
>
> thanks in advance for your help,
> Luis
> >
>
--
Science answers questions; philosophy questions answers.