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);
The callback function runs later on from a global scope, so the return won’t do anything useful.
Try replacing the return with the alert instead.