所以我这样做:
function loginFunc(userNameOrEmail, passWord){
var emailOrUserNameV = encodeURIComponent(userNameOrEmail);
var passWordV = encodeURIComponent(passWord);
$.getJSON("http://mysite.com/pullData/login.php?callback=?",
{
emailOrUserName: emailOrUserNameV,
passWord: passWordV
},
function(recievedData) {
if(recievedData[0] == 'true'){
return true;
}
else{
return false;
}
});
}
然后我这样做:
$('#loginBtnHtml').click(function(){
var emailVar = $('#email_html').val();
var pwdVar = $('#password_html').val();
if(loginFunc(emailVar, pwdVar)){
alert('good');
}
else{
alert('bad');
}
});
如果我loginFunc()
用它运行alert(recievedData[0]);
它工作正常,我如何让它返回 bool 到$('#loginBtnHtml').click();
?
当我这样做进行故障排除时:
$('#loginBtnHtml').click(function(){
var emailVar = $('#email_html').val();
var pwdVar = $('#password_html').val();
var whatIsBeingReturned = loginFunc(emailVar, pwdVar);
alert(whatIsBeingReturned);
});
它以“未定义”警告...不确定我做错了什么。