$.post("general.php", {/* some values */}, function(data){var id = data;});
alert(id);
The problem is that, alert is empty. Do know anyone why? And how to fix it? Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are 2 problems :
one is that the ajax is asynchronous and the alert executes before the ajax callback, where the
idvariable is being setthe second one is that the variable is not global, it is only visible in the callback scope
So, I suggest you declare the variable global (if you need it for later use) :
or
And you should probably execute the logic in the callback :