I want to create an javaScript object to manage MySQL database table. In doing that I have coded the following script in which I call the ajax ''Ajax.Request'' call to get the table metadata and to update the object attribute (this.tableMetaData) with what is returend from the Ajax request. However it seems that Ajax.Request change the scope of functions to ''window'' and as a result this.tableMetaData attribute is not identified by the onSuccess function as a property of the current object. How can I inform the onSuccess function that this.tableMetaData is an attribute of the current object? function table(tableName){ this.tableName = tableName; this.tableMetaData =""; this.inputFields = new Array(); // Get the table metadata var myRequest = new Ajax.Request(''tableManager.php'', { method: ''post'', parameters: { Mode:''getMetaData'',table: this.tableName}, onSuccess: function(transport){ this.tableMetaData = transport, }, onFailure: function(){ this.error("Table object construction failed"); } }); } --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Nikodim Lazarov
2008-Feb-23 09:49 UTC
Re: Ajax in JavaScript object supported in prototype.
Hi, Try binding the onSuccess function with ''this'': onSuccess: function(transport){ this.tableMetaData = transport, }.bind(this) Thus you will keep the scope at the current object. Regards, Niko On Sat, 23 Feb 2008 11:41:05 +0200, damitha <ddk-QK3ekNSdwAhieFqLg3alkQ@public.gmane.org> wrote:> > I want to create an javaScript object to manage MySQL database table. > In doing that I have coded the following script in which I call the > ajax ''Ajax.Request'' call to get the table metadata and to update the > object attribute (this.tableMetaData) with what is returend from the > Ajax request. However it seems that Ajax.Request change the scope of > functions to ''window'' and as a result this.tableMetaData attribute is > not identified by the onSuccess function as a property of the current > object. How can I inform the onSuccess function that > this.tableMetaData is an attribute of the current object? > > > function table(tableName){ > this.tableName = tableName; > this.tableMetaData =""; > this.inputFields = new Array(); > > // Get the table metadata > > > var myRequest = new Ajax.Request(''tableManager.php'', { > method: ''post'', > parameters: { Mode:''getMetaData'',table: this.tableName}, > onSuccess: function(transport){ > this.tableMetaData = transport, }, > onFailure: function(){ > this.error("Table object construction failed"); > } > }); > > } > > > >-- Best Regards, Nikodim Lazarov --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks, It works On Feb 23, 3:49 pm, "Nikodim Lazarov" <nlaza...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi, > > Try binding the onSuccess function with ''this'': > > onSuccess: function(transport){ > this.tableMetaData = transport, }.bind(this) > > Thus you will keep the scope at the current object. > > Regards, > Niko > > > > > > On Sat, 23 Feb 2008 11:41:05 +0200, damitha <d...-QK3ekNSdwAhieFqLg3alkQ@public.gmane.org> wrote: > > > I want to create an javaScript object to manage MySQL database table. > > In doing that I have coded the following script in which I call the > > ajax ''Ajax.Request'' call to get the table metadata and to update the > > object attribute (this.tableMetaData) with what is returend from the > > Ajax request. However it seems that Ajax.Request change the scope of > > functions to ''window'' and as a result this.tableMetaData attribute is > > not identified by the onSuccess function as a property of the current > > object. How can I inform the onSuccess function that > > this.tableMetaData is an attribute of the current object? > > > function table(tableName){ > > this.tableName = tableName; > > this.tableMetaData =""; > > this.inputFields = new Array(); > > > // Get the table metadata > > > var myRequest = new Ajax.Request(''tableManager.php'', { > > method: ''post'', > > parameters: { Mode:''getMetaData'',table: this.tableName}, > > onSuccess: function(transport){ > > this.tableMetaData = transport, }, > > onFailure: function(){ > > this.error("Table object construction failed"); > > } > > }); > > > } > > -- > Best Regards, > Nikodim Lazarov- Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---