Forum: Rails Spinoffs (closed, excessive spam) Prototype - give parameters to a callback

Posted by ljundie (Guest)
on 2008-06-26 20:13
(Received via mailing list)
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
Posted by Matt Foster (Guest)
on 2008-06-26 21:10
(Received via mailing list)
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
Posted by Frederick Polgardy (Guest)
on 2008-06-26 21:20
(Received via mailing list)
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.
Posted by ljundie (Guest)
on 2008-06-29 10:10
(Received via mailing list)
hi!

both options work fine, many thanks for your help :)
This topic is locked and can not be replied to.