Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.