Javascript变量范围,如何将变量值传递给外部函数?

时间:2015-03-07 20:43:07

标签: javascript

如何让变量等于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");

}

0 个答案:

没有答案