I want to have a global object that can be updated via Ajax: var globalObject; function updateObject (id) { new Ajax.Request(''url'', { parameters: {id: id}, onSuccess: function(transport) { globalObject = transport.responseText.evalJSON(); }}); } That never seems to work though, why not? Thanks! --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
That should actually work unless there''s another "globalObject" in the scope of callback function. Are you sure a proper response comes from the server? - kangax On Jun 26, 3:25 am, Namotco <namo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I want to have a global object that can be updated via Ajax: > > var globalObject; > > function updateObject (id) { > new Ajax.Request(''url'', { parameters: {id: id}, onSuccess: > function(transport) { > globalObject = transport.responseText.evalJSON(); > > }}); > } > > That never seems to work though, why not? > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
When are you verifying its value, it will be undefined until the ajax request has come back to the onSuccess handler. -- Matt Foster Ajax Engineer Nth Penguin, LLC http://www.nthpenguin.com On Jun 26, 7:47 am, kangax <kan...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> That should actually work unless there''s another "globalObject" in the > scope of callback function. Are you sure a proper response comes from > the server? > > - kangax > > On Jun 26, 3:25 am, Namotco <namo...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I want to have a global object that can be updated via Ajax: > > > var globalObject; > > > function updateObject (id) { > > new Ajax.Request(''url'', { parameters: {id: id}, onSuccess: > > function(transport) { > > globalObject = transport.responseText.evalJSON(); > > > }}); > > } > > > That never seems to work though, why not? > > > Thanks!--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---