I have a global variable I intend to alter from inside an AJAX callback but I haven’t had much luck with it. I’ve tried accessing it through the window object but when I console log the variable from within that callback, it logs the changes meaning the variable was perceived as coming from the local scope. I’ve also tried declaring it specifically with the var
keyword but that doesn’t work. How do I get around it? My code below
var error = false, postSuccess = false, replace;
function post () {
$.post('new_comment.php', {new_comment: typedText, parent_post: thisPost}, function(e) {
window.postSuccess = true;
}
function loadingComment () {
post ();
if (postSuccess == true) {
console.log("post just ran", postSuccess); // Logs false
}