> > var gljson;
> > var url = '/my/path/here';
> > var ajobj = new Ajax.Request(
> > url,
> > {
> > method: 'get',
> > onComplete: setMakeVars
> > });
> >
> > function setMakeVars (transport) {
> > var json = eval(transport.responseText);
> > gljson = json;
> > }
> >
> > alert(gljson); // is undefined
> >
That alert is being called before the ajax request finishes (if you told
it to send it synchronously instead of asynchronously, it would wait
until it finished before it moved on to run the alert).
Test it like this:
var gljson;
var url = '/my/path/here';
var ajobj = new Ajax.Request(
url,
{
method: 'get',
onComplete: setMakeVars
});
function setMakeVars (transport) {
var json = eval(transport.responseText);
gljson = json;
alert(json);
testGlobal();
}
function testGlobal () {
alert(gljson);
}
That should tell you if it is persisting. The first alert lets you know
if the eval worked, then you call another function and alert the global
variable to see if it has a value.
Greg
_______________________________________________
Rails-spinoffs mailing list
[email protected]
http://lists.rubyonrails.org/mailman/listinfo/rails-spinoffs