Jump to content

Make variable global


unemployment

Recommended Posts

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);

Link to comment
https://forums.phpfreaks.com/topic/238133-make-variable-global/
Share on other sites

You cannot assume that the AJAX happens immediately. When you call .get the process will start but you can't know when it will complete. Meanwhile the rest of your code continues executing.

 

If you need stuff to happen when the AJAX completes then put the code inside the callback function.

You cannot assume that the AJAX happens immediately. When you call .get the process will start but you can't know when it will complete. Meanwhile the rest of your code continues executing.

 

If you need stuff to happen when the AJAX completes then put the code inside the callback function.

 

I understand what you mean by completing, but I don't have a clue on what you mean when you say call back function.  Please explain

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.