How can I get the variable to be equal to what is defined in the if statement? My first alert evaluates correctly but then loses scope. I need to take action outside of the $.get function.
function emailCheck() {
var emailExists;
var emailEntry = $("#email").val();
$.getJSON('http://localhost:8080/ShoppingCart/ajax.do', function(responseJson) {
$.each(responseJson, function(index, item) {
if(emailEntry == item.email) {
//Set to true when a match is found
emailExists = true;
return false;
}
});
//alerts to true
alert(emailExists + " in get");
});
//Need emailExists to be true here when match is found but it's undefined??
alert(emailExists + "end email check");
}