我试图在true
,false
bool结果的基础上对ajax成功函数做一些事情。
当我跨数据库检查电子邮件时 -
功能 -
public bool RegisterEmail(string email) {
var registeredemail = (from u in db.FunRegistereds
where u.EmailAddress == email
select u).ToList();
if (registeredemail.Count() == 0 && registeredemail == null) {
return false;
}
else {
return true;
}
}
Ajax处理 -
$(function () {
$('#exist-email').on('keyup', function () {
var email = $('#exist-email').val();
$.ajax({
url: '/Account/RegisterEmail/?email=' + email,
type: 'post',
success: function (data) {
if (!data) {
$('.avalibility-email').html("<h2>" + "'" + email + "'" + "</h2>" + " Is" + "<b>" + " not" + "</b>" + "</b>" + " available for email address.");
} else {
$('.avalibility-email').html("<h2>" + "'" + email + "'" + "</h2>" + " Is" + "<b>" + " available " + "</b>" + "</b>" + "for email address.");
}
}
});
});
});
但我没有根据true
或false
获得结果。
答案 0 :(得分:0)
可能会在这条线上出错?
if (registeredemail.Count == 0 && registeredemail == null) {
必须是这样的:
if (registeredemail == null || registeredemail.Count == 0) {