I'm having trouble with some code. I'm using console.log() to output the variables contents but it seems like $.post() is taking to long thus my variable isn't being set properly. Here is my code.
$.tmsmm = {
duplicate_meeting : "something"
};
$.post("scripts/check_duplicate_meetings.php", { meeting_date: meeting_date, meeting_type: meeting_type }, function(data) {
$.tmsmm.duplicate_meeting = data;
console.log("myVar: " + $.tmsmm.duplicate_meeting);
});
console.log("myVar2: " + $.tmsmm.duplicate_meeting);
What's outputted:
myVar2: something
myVar: this is ajax data!
As you can see, myVar2 is being logged before myVar. How do I get around this?
UPDATE: The reason this solutions suited my situation best vs calling a function upon success or completion using $.post is that i have a lot of code that comes after this sample that is dependent upon the variables value. I only logged the value 2 different times to troubleshoot why my variable wasnt set outside of the $.post function. Thank you all for your help!