ajax检测账户是否存在

Register.cshtml

<div title="账户">
     账户
   <input type="text" name="Acc_account" placeholder="账户" 
onkeyup="this.value = this.value.replace(/[^w./]/ig, ''); is_account_exist(this.value);" /> </div>

 

 VerifyAccount.js

$(document).ready(function () { 
$("#next_btn_01").click(function () {if (is_account_exist(acc_account)) return;
        }
//判断账户是否存在
function is_account_exist(acc_account) {
    var is_exist = false;
    Ajax.post(
        '/Account/CheckAccountIfExist',
        { Acc_account: acc_account },
        function (r) {
            is_exist = r.account_exist;
            if (is_exist) $('.next_error_01').show();
            else
                $('.next_error_01').hide();
        },
        undefined,
        false
        );

    return is_exist;
}
})

AccountControl.cs

        private IAccountService _accountService { get; set; }

#region
检测账户是否存在 public ActionResult CheckAccountIfExist(string Acc_account) { if (_accountService.GetByAccount(Acc_account) != null) { JsonResult["account_exist"] = true; } else { JsonResult["account_exist"] = false; } return Json(JsonResult); } #endregion

 

原文地址:https://www.cnblogs.com/wiming/p/4213598.html