That should work just fine. However... You didn't show the code that tries to use the globalX variable, and that is probably where the problem lies. Does the overall flow of your code look like this perhaps?
var globalX; function foo() { $.getJSON("jsondata.js",function(data){ globalX = data; }); } alert( globalX ); That won't work, because the alert() is called *before* the asynchronous getJSON callback. OTOH, this would work: var globalX; function foo() { $.getJSON("jsondata.js",function(data){ globalX = data; dataReady(); }); } function dataReady() { alert( globalX ); } Now the alert() is called after the globalX data is ready. But since you have to use a callback like this anyway, you may not need the global variable at all. After all, this code: function foo() { $.getJSON("jsondata.js",function(data){ alert( data ); }); } would obviously work, as would this: var globalX; function foo() { $.getJSON("jsondata.js", dataReady); } function dataReady( data ) { alert( data ); } -Mike > -----Original Message----- > From: jquery-en@googlegroups.com > [mailto:[EMAIL PROTECTED] On Behalf Of funkadelic > Sent: Thursday, March 27, 2008 4:19 PM > To: jQuery (English) > Subject: [jQuery] assigning data from $.getJSON() to a global > variable? > > > Hi, > > Is there a way to take the JSON from a $.getJSON() call and > assign it to a var in the global scope? > > i tried the following but it didn't work: > > var globalX; > > function foo() { > $.getJSON("jsondata.js",function(data){ > globalX = data; > }); > } > > thanks >