Forum: Rails Spinoffs (closed, excessive spam) getting AJAX/JSON into global var

Posted by Namotco (Guest)
on 2008-06-26 09:26
(Received via mailing list)
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!
Posted by kangax (Guest)
on 2008-06-26 13:47
(Received via mailing list)
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
Posted by Matt Foster (Guest)
on 2008-06-26 18:19
(Received via mailing list)
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
This topic is locked and can not be replied to.