var doCheck = function() {
var data;
$.ajax({
url: 'check.php',
data: 'ch=check',
success: function(resp) {
data = resp;
}
});
console.log(data);
return data == 1;
};
The above code, regardless of the data only ever returns a 0 or a 1. Within the scope of the success callback, this is true. The argument resp has a value of 0 or 1 depending on input.
However, whenever I try to access a private variable (should not be affected by scope), nothing happens; and when console.log(data); is called all that is written to the console is undefined.
This function has no parent, so don't worry about some other kind of scope interference.