Hi, is it possible to get some "user"-arguments on the "onSuccess"-method of the Ajax.request object? Something like this (look out for "mydata"): ------------------------------------------------------------------------------------------------------------------------------------------------- var mydata_class = Class.create(); mydata_class .prototype ={ initialize:function(){ this.Images=null; } }; var mydata = new mydata_class() new Ajax.Request("/system/classes/d4pc/Misc/DiaShow/API.php", { method:''get'', parameters:request, onSuccess:Update_onSuccess(response,mydata), onFailure:this.DiaUpdate_onFailure } ); function Update_onSuccess(response,mydata){ var rpc= eval (''(''+response.responseText+'')''); mydata.someproperty= rpc.images; }; ------------------------------------------------------------------------------------------------------------------------------------------------- If I do so, "response" will be empty. Is there a way to get this thing done? Andreas --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Sherif Zaroubi
2007-Mar-14 16:54 UTC
Re: "user"-arguments on the "onSuccess"-method possible?
You could try: new Ajax.Request("/system/classes/d4pc/Misc/DiaShow/API.php", { method:''get'', parameters:request, onSuccess:function(response){Update_onSuccess(response,mydata);}, onFailure:this.DiaUpdate_onFailure } ) I''m not sure on the exact syntax, but that is the trip I have used in the past. Create an anonymous method that calls the correct one with the correct parameters.> -----Original Message----- > From: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails- > spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Andreas Franke > Sent: Wednesday, March 14, 2007 10:46 AM > To: Ruby on Rails: Spinoffs > Subject: [Rails-spinoffs] "user"-arguments on the "onSuccess"-method > possible? > > > Hi, > is it possible to get some "user"-arguments on the "onSuccess"-method > of the Ajax.request object? > Something like this (look out for "mydata"): > -------------------------------------------------------------------------- > ----------------------------------------------------------------------- > var mydata_class = Class.create(); > mydata_class .prototype ={ > initialize:function(){ > this.Images=null; > } > }; > > var mydata = new mydata_class() > > new Ajax.Request("/system/classes/d4pc/Misc/DiaShow/API.php", > { > method:''get'', > parameters:request, > onSuccess:Update_onSuccess(response,mydata), > onFailure:this.DiaUpdate_onFailure > } > ); > > function Update_onSuccess(response,mydata){ > var rpc= eval (''(''+response.responseText+'')''); > mydata.someproperty= rpc.images; > }; > -------------------------------------------------------------------------- > ----------------------------------------------------------------------- > > If I do so, "response" will be empty. Is there a way to get this thing > done? > > Andreas > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Andreas Franke
2007-Mar-14 17:54 UTC
AW: [Rails-spinoffs] Re: "user"-arguments on the "onSuccess"-methodpossible?
Hi, I''ve tried your code, but it didn`t work. Like my own code ;-) The second parameter works fine, but the ajax.request-result is empty. I''ve postet my complete code to specify what i want. ____________________________________________________________________________ ______________ var d4pc_Misc_DiaShow = Class.create(); d4pc_Misc_DiaShow.prototype = { initialize:function(){; this.DiaShows=null; this.Images=null; this.ID1=null; this.ID2=null; this.FXDuration=1; this.DiaShowUpdater=null; this.DiaShowPosition=null; this.ActiveID=null; this.ZIndex=10; }, toggleActiveID:function(){ if (this.ActiveID==this.ID1){ this.ActiveID=this.ID2; } else{ this.ActiveID=this.ID1; }; }, DiaFadeIn:function(id,dur){ new Effect.Appear(id,{duration: dur}); }, DiaFadeOut:function(id,dur){ new Effect.Fade(id,{duration: dur}); }, DiaUpdate_onSuccess:function(response,obj){ //Just check what''s comes in here alert (response.responseText+" | "+Object.toJSON(obj)); //do the other things i want to do if it works... }, DiaUpdate_onFailure:function(response){ alert ("Fehler..."); }, DiaShowUpdate:function(){ }, runDiaShow:function (id1,id2,dur,show){ this.ID1 = id1; this.ID2 = id2; this.ActiveID = this.ID2; this.FXDuration = dur; var r=Hash.toQueryString({RPC:''{"method":"getImages","DiaShow":"''+show+''","id":'' +(new Date().getTime())+''}''}); var request =Hash.toQueryString({command:r}); new Ajax.Request("/system/classes/d4pc/Misc/DiaShow/API.php", { method:''get'', parameters:request, onSuccess:function(response){DiaUpdate_onSuccess(response,this)}, onFailure:this.DiaUpdate_onFailure } ); } }; var diashow = new d4pc_Misc_DiaShow(); Diashow.runDiaShow("Dia1","Dia2",3,"myshow"); ____________________________________________________________________________ ______________ -----Ursprüngliche Nachricht----- Von: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] Im Auftrag von Sherif Zaroubi Gesendet: Mittwoch, 14. März 2007 17:55 An: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Betreff: [Rails-spinoffs] Re: "user"-arguments on the "onSuccess"-methodpossible? You could try: new Ajax.Request("/system/classes/d4pc/Misc/DiaShow/API.php", { method:''get'', parameters:request, onSuccess:function(response){Update_onSuccess(response,mydata);}, onFailure:this.DiaUpdate_onFailure } ) I''m not sure on the exact syntax, but that is the trip I have used in the past. Create an anonymous method that calls the correct one with the correct parameters.> -----Original Message----- > From: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails- > spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] On Behalf Of Andreas Franke > Sent: Wednesday, March 14, 2007 10:46 AM > To: Ruby on Rails: Spinoffs > Subject: [Rails-spinoffs] "user"-arguments on the "onSuccess"-method > possible? > > > Hi, > is it possible to get some "user"-arguments on the "onSuccess"-method > of the Ajax.request object? > Something like this (look out for "mydata"): > ---------------------------------------------------------------------- > ---- > ---------------------------------------------------------------------- > - > var mydata_class = Class.create(); > mydata_class .prototype ={ > initialize:function(){ > this.Images=null; > } > }; > > var mydata = new mydata_class() > > new Ajax.Request("/system/classes/d4pc/Misc/DiaShow/API.php", > { > method:''get'', > parameters:request, > onSuccess:Update_onSuccess(response,mydata), > onFailure:this.DiaUpdate_onFailure > } > ); > > function Update_onSuccess(response,mydata){ > var rpc= eval (''(''+response.responseText+'')''); > mydata.someproperty= rpc.images; > }; > ---------------------------------------------------------------------- > ---- > ---------------------------------------------------------------------- > - > > If I do so, "response" will be empty. Is there a way to get this thing > done? > > Andreas > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Andreas Franke
2007-Mar-14 18:06 UTC
AW: [Rails-spinoffs] Re: "user"-arguments on the "onSuccess"-methodpossible?
Yes you are right, But than i have to code mydata hard to Update_onSuccess and that''s bad because i want to build an DiaShow-class to have eventually a number of instances running on one Page. If i do so like you have shown me, all instances will use the same "mydata", and than the trouble begins... Look at this and it will be clear i think: ____________________________________________________________________________ ______________ var d4pc_Misc_DiaShow = Class.create(); d4pc_Misc_DiaShow.prototype = { initialize:function(){; this.DiaShows=null; this.Images=null; this.ID1=null; this.ID2=null; this.FXDuration=1; this.DiaShowUpdater=null; this.DiaShowPosition=null; this.ActiveID=null; this.ZIndex=10; }, toggleActiveID:function(){ if (this.ActiveID==this.ID1){ this.ActiveID=this.ID2; } else{ this.ActiveID=this.ID1; }; }, DiaFadeIn:function(id,dur){ new Effect.Appear(id,{duration: dur}); }, DiaFadeOut:function(id,dur){ new Effect.Fade(id,{duration: dur}); }, DiaUpdate_onSuccess:function(response,obj){ //Just check what''s comes in here alert (response.responseText+" | "+Object.toJSON(obj)); //do the other things i want to do if it works... }, DiaUpdate_onFailure:function(response){ alert ("Fehler..."); }, DiaShowUpdate:function(){ }, runDiaShow:function (id1,id2,dur,show){ this.ID1 = id1; this.ID2 = id2; this.ActiveID = this.ID2; this.FXDuration = dur; var r=Hash.toQueryString({RPC:''{"method":"getImages","DiaShow":"''+show+''","id":'' +(new Date().getTime())+''}''}); var request =Hash.toQueryString({command:r}); new Ajax.Request("/system/classes/d4pc/Misc/DiaShow/API.php", { method:''get'', parameters:request, //Now here comes what i want, if it''s possible: onSuccess:this.DiaUpdate_onSuccess(response,this), onFailure:this.DiaUpdate_onFailure } ); } }; var diashow = new d4pc_Misc_DiaShow(); Diashow.runDiaShow("Dia1","Dia2",3,"myshow"); ____________________________________________________________________________ ______________ -----Ursprüngliche Nachricht----- Von: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org [mailto:rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org] Im Auftrag von Colin Mollenhour Gesendet: Mittwoch, 14. März 2007 19:42 An: rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org Betreff: [Rails-spinoffs] Re: "user"-arguments on the "onSuccess"-methodpossible? If you reference a variable that exists outside of the function declaration, it will create a closure, so any time that function is called it will be acting on that variable even though it is outside the functions scope. This is how Prototype''s "bind" function works, which could also be used here to "bind" extra variables to that function. var mydata = new mydata_class(); function Update_onSuccess(response){ //don''t add "mydata" as an argument var rpc= eval (''(''+response.responseText+'')''); mydata.someproperty= rpc.images; //this creates a "closure" around "mydata" }; //now any time Update_onSuccess is called, it is as if mydata was passed as an argument new Ajax.Request("/system/classes/d4pc/Misc/DiaShow/API.php", { method:''get'', parameters:request, onSuccess: Update_onSuccess, //just pass the function itself, it already has access to mydata onFailure: this.DiaUpdate_onFailure }); Colin Andreas Franke wrote:> Hi, > is it possible to get some "user"-arguments on the "onSuccess"-method > of the Ajax.request object? > Something like this (look out for "mydata"): > ---------------------------------------------------------------------- > ---------------------------------------------------------------------- > ----- > var mydata_class = Class.create(); > mydata_class .prototype ={ > initialize:function(){ > this.Images=null; > } > }; > > var mydata = new mydata_class() > > new Ajax.Request("/system/classes/d4pc/Misc/DiaShow/API.php", > { > method:''get'', > parameters:request, > onSuccess:Update_onSuccess(response,mydata), > onFailure:this.DiaUpdate_onFailure > } > ); > > function Update_onSuccess(response,mydata){ > var rpc= eval (''(''+response.responseText+'')''); > mydata.someproperty= rpc.images; > }; > ---------------------------------------------------------------------- > ---------------------------------------------------------------------- > ----- > > If I do so, "response" will be empty. Is there a way to get this thing > done? > > Andreas > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Colin Mollenhour
2007-Mar-14 18:42 UTC
Re: "user"-arguments on the "onSuccess"-method possible?
If you reference a variable that exists outside of the function declaration, it will create a closure, so any time that function is called it will be acting on that variable even though it is outside the functions scope. This is how Prototype''s "bind" function works, which could also be used here to "bind" extra variables to that function. var mydata = new mydata_class(); function Update_onSuccess(response){ //don''t add "mydata" as an argument var rpc= eval (''(''+response.responseText+'')''); mydata.someproperty= rpc.images; //this creates a "closure" around "mydata" }; //now any time Update_onSuccess is called, it is as if mydata was passed as an argument new Ajax.Request("/system/classes/d4pc/Misc/DiaShow/API.php", { method:''get'', parameters:request, onSuccess: Update_onSuccess, //just pass the function itself, it already has access to mydata onFailure: this.DiaUpdate_onFailure }); Colin Andreas Franke wrote:> Hi, > is it possible to get some "user"-arguments on the "onSuccess"-method > of the Ajax.request object? > Something like this (look out for "mydata"): > ------------------------------------------------------------------------------------------------------------------------------------------------- > var mydata_class = Class.create(); > mydata_class .prototype ={ > initialize:function(){ > this.Images=null; > } > }; > > var mydata = new mydata_class() > > new Ajax.Request("/system/classes/d4pc/Misc/DiaShow/API.php", > { > method:''get'', > parameters:request, > onSuccess:Update_onSuccess(response,mydata), > onFailure:this.DiaUpdate_onFailure > } > ); > > function Update_onSuccess(response,mydata){ > var rpc= eval (''(''+response.responseText+'')''); > mydata.someproperty= rpc.images; > }; > ------------------------------------------------------------------------------------------------------------------------------------------------- > > If I do so, "response" will be empty. Is there a way to get this thing > done? > > Andreas > > > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Colin Mollenhour
2007-Mar-14 19:41 UTC
Re: AW: [Rails-spinoffs] Re: "user"-arguments on the "onSuccess"-methodpossible?
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> Then use bind as I previously mentioned. <a class="moz-txt-link-freetext" href="http://prototypejs.org/api/function/bind">http://prototypejs.org/api/function/bind</a><br> <br> <pre wrap="">d4pc_Misc_DiaShow.prototype = { ... DiaUpdate_onSuccess:function(response,obj){ this.someProperty = <something>; //"this" is the same "this" that you passed to "bind" below }, runDiaShow:function (id1,id2,dur,show){ ... Ajax.Request("/system/classes/d4pc/Misc/DiaShow/API.php",{ method:''get'', parameters:request, //Now here comes what i want, if it''s possible: onSuccess:this.DiaUpdate_onSuccess.bind(this), //bind the function''s "this" property onFailure:this.DiaUpdate_onFailure }); } }; </pre> Colin<br> <br> Andreas Franke wrote: <blockquote cite="mid:E0993773B8304C0F95B46E89747F75A9@DOC4PCNOTEBOOK" type="cite"> <pre wrap="">Yes you are right, But than i have to code mydata hard to Update_onSuccess and that''s bad because i want to build an DiaShow-class to have eventually a number of instances running on one Page. If i do so like you have shown me, all instances will use the same "mydata", and than the trouble begins... Look at this and it will be clear i think: ____________________________________________________________________________ ______________ var d4pc_Misc_DiaShow = Class.create(); d4pc_Misc_DiaShow.prototype = { initialize:function(){; this.DiaShows=null; this.Images=null; this.ID1=null; this.ID2=null; this.FXDuration=1; this.DiaShowUpdater=null; this.DiaShowPosition=null; this.ActiveID=null; this.ZIndex=10; }, toggleActiveID:function(){ if (this.ActiveID==this.ID1){ this.ActiveID=this.ID2; } else{ this.ActiveID=this.ID1; }; }, DiaFadeIn:function(id,dur){ new Effect.Appear(id,{duration: dur}); }, DiaFadeOut:function(id,dur){ new Effect.Fade(id,{duration: dur}); }, DiaUpdate_onSuccess:function(response,obj){ //Just check what''s comes in here alert (response.responseText+" | "+Object.toJSON(obj)); //do the other things i want to do if it works... }, DiaUpdate_onFailure:function(response){ alert ("Fehler..."); }, DiaShowUpdate:function(){ }, runDiaShow:function (id1,id2,dur,show){ this.ID1 = id1; this.ID2 = id2; this.ActiveID = this.ID2; this.FXDuration = dur; var r=Hash.toQueryString({RPC:''{"method":"getImages","DiaShow":"''+show+''","id":'' +(new Date().getTime())+''}''}); var request =Hash.toQueryString({command:r}); new Ajax.Request("/system/classes/d4pc/Misc/DiaShow/API.php", { method:''get'', parameters:request, //Now here comes what i want, if it''s possible: onSuccess:this.DiaUpdate_onSuccess(response,this), onFailure:this.DiaUpdate_onFailure } ); } }; var diashow = new d4pc_Misc_DiaShow(); Diashow.runDiaShow("Dia1","Dia2",3,"myshow"); ____________________________________________________________________________ ______________ -----Ursprüngliche Nachricht----- Von: <a class="moz-txt-link-abbreviated" href="mailto:rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org">rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org</a> [<a class="moz-txt-link-freetext" href="mailto:rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org">mailto:rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org</a>] Im Auftrag von Colin Mollenhour Gesendet: Mittwoch, 14. März 2007 19:42 An: <a class="moz-txt-link-abbreviated" href="mailto:rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org">rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org</a> Betreff: [Rails-spinoffs] Re: "user"-arguments on the "onSuccess"-methodpossible? If you reference a variable that exists outside of the function declaration, it will create a closure, so any time that function is called it will be acting on that variable even though it is outside the functions scope. This is how Prototype''s "bind" function works, which could also be used here to "bind" extra variables to that function. var mydata = new mydata_class(); function Update_onSuccess(response){ //don''t add "mydata" as an argument var rpc= eval (''(''+response.responseText+'')''); mydata.someproperty= rpc.images; //this creates a "closure" around "mydata" }; //now any time Update_onSuccess is called, it is as if mydata was passed as an argument new Ajax.Request("/system/classes/d4pc/Misc/DiaShow/API.php", { method:''get'', parameters:request, onSuccess: Update_onSuccess, //just pass the function itself, it already has access to mydata onFailure: this.DiaUpdate_onFailure }); Colin Andreas Franke wrote: </pre> <blockquote type="cite"> <pre wrap="">Hi, is it possible to get some "user"-arguments on the "onSuccess"-method of the Ajax.request object? Something like this (look out for "mydata"): ---------------------------------------------------------------------- ---------------------------------------------------------------------- ----- var mydata_class = Class.create(); mydata_class .prototype ={ initialize:function(){ this.Images=null; } }; var mydata = new mydata_class() new Ajax.Request("/system/classes/d4pc/Misc/DiaShow/API.php", { method:''get'', parameters:request, onSuccess:Update_onSuccess(response,mydata), onFailure:this.DiaUpdate_onFailure } ); function Update_onSuccess(response,mydata){ var rpc= eval (''(''+response.responseText+'')''); mydata.someproperty= rpc.images; }; ---------------------------------------------------------------------- ---------------------------------------------------------------------- ----- If I do so, "response" will be empty. Is there a way to get this thing done? Andreas </pre> <pre wrap=""> </pre> </blockquote> <pre wrap=""><!----> </pre> </blockquote> <br> --~--~---------~--~----~------------~-------~--~----~<br> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. <br> To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en <br> -~----------~----~----~----~------~----~------~--~---<br> </body> </html> <br>