如何让变量等于if语句中定义的变量?我的第一个警报正确评估,但随后失去了范围。我需要在$ .get函数之外采取行动。
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");
}