K
kevinold
Hello everyone,
I'm using the Prototype JS library, but think my problem might be just
be with how I'm initializing and trying to set my javascript variables.
Just a note, I have to pass my JSON in the response body. I'm aware
of the X-JSON header, but am passing too much data to use it. No
problem and I have code that has it working well.
While I'm getting my JSON data back and can do whatever I'd like with
it in "setMakeVars", I'd like to set it to a global var "gljson"
below, but it never gets set.
Everything with the request is fine and there is data in the "json"
var in "setMakeVars", but it's almost like "setMakeVars" doesn't have
access to global vars.
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
Has anyone else run into this? Any ideas what I can do to fix it?
Thanks for any help,
Kevin
I'm using the Prototype JS library, but think my problem might be just
be with how I'm initializing and trying to set my javascript variables.
Just a note, I have to pass my JSON in the response body. I'm aware
of the X-JSON header, but am passing too much data to use it. No
problem and I have code that has it working well.
While I'm getting my JSON data back and can do whatever I'd like with
it in "setMakeVars", I'd like to set it to a global var "gljson"
below, but it never gets set.
Everything with the request is fine and there is data in the "json"
var in "setMakeVars", but it's almost like "setMakeVars" doesn't have
access to global vars.
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
Has anyone else run into this? Any ideas what I can do to fix it?
Thanks for any help,
Kevin