在 下validateMail()
,变量chump
正在返回undefined
,但它应该是 true 或 false 值。
我不明白,因为alert()
两个条件语句下的语句finalFlash()
工作正常,我在那里得到一个真值或假值。
<script>
function validateRecipient()
{
var recipient=document.messageForm.recipient.value;
if (recipient==null || recipient=="")
{
document.getElementById("recipientError").innerHTML='<div style="font-size:13px; color:#b94a48; clear:both">Please enter a username</div>';
document.getElementById("recipient_error").className="control-group error";
return false;
}
else
{
document.getElementById("recipientError").innerHTML="";
document.getElementById("recipient_error").className="control-group";
return true;
}
}
function validateMessage()
{
var message=document.messageForm.message.value;
if (message==null || message=="")
{
document.getElementById("messageError").innerHTML='<div style="font-size:13px; color:#b94a48; clear:both">Please enter a message</div>';
document.getElementById("message_error").className="control-group error";
return false;
}
else
{
document.getElementById("messageError").innerHTML="";
document.getElementById("message_error").className="control-group";
return true;
}
}
function validateMail()
{
var items = [validateRecipient(), validateMessage(), validateUser()];
var chump = validateUser()
alert(chump)
for (var i in items)
{
var item = items[i];
item
}
if (validateRecipient() && validateMessage() && validateUser())
{
return true;
}
return false;
}
function validateUser(){
$.get("/trivia/xhr_test/",
{
username: document.messageForm.recipient.value
},
function(data){
return finalFlash(data); // edit suggested by Aamir Adnan
});
}
function finalFlash(data){
if (data == "True")
{
document.getElementById("recipientError").innerHTML="";
document.getElementById("recipient_error").className="control-group";
alert(true)
return true
}
else if (data != null && data != "" && data == "False")
{
document.getElementById("recipientError").innerHTML='<div style="font-size:13px; color:#b94a48; clear:both">That username does not exist</div>';
document.getElementById("recipient_error").className="control-group error";
alert(false)
return false
}
}
</script>