Page 1 of 1

Make Variable Global

Posted: Wed Jun 01, 2011 7:38 pm
by unemployment
How can I make my alert work? Right now it is undefined and I need to make my function in the variable global. Can this be done?
if (json_goals === undefined)
{
	ajax.get('/assets/ajax/user_goals.php', function (resp)
	{
		var json_goals = resp;
			
		return json_goals;
	});
}
alert(json_goals);

Re: Make Variable Global

Posted: Wed Jun 01, 2011 7:59 pm
by unemployment
Fixed... no worries

Re: Make Variable Global

Posted: Thu Jun 02, 2011 3:16 pm
by jacek
And for people who fund this page via google the solution is to declare the variable outside of a function.
var this_is_global = true;

function Im_a_function(){
    // here you can use the variable this_is_global.
}