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?
[syntax=javascript]
if (json_goals === undefined)
{
ajax.get('/assets/ajax/user_goals.php', function (resp)
{
var json_goals = resp;
return json_goals;
});
}
alert(json_goals);[/syntax]
Make Variable Global
-
- Posts: 165
- Joined: Fri May 06, 2011 5:02 pm
Re: Make Variable Global
Fixed... no worries
Re: Make Variable Global
And for people who fund this page via google the solution is to declare the variable outside of a function.
[syntax=javascript]var this_is_global = true;
function Im_a_function(){
// here you can use the variable this_is_global.
}[/syntax]
[syntax=javascript]var this_is_global = true;
function Im_a_function(){
// here you can use the variable this_is_global.
}[/syntax]