受欢迎的博客标签

step 1:导入jquery

<script src="~/lib/jquery/dist/jquery-3.3.1.js" type="text/javascript"></script>

step 2:在js脚本中写Ajax

function FormAjax(){
    $.ajax({
        url: "Register/RegisterResult",
        data: {
            "phone": phone, "verification_code": verification_code,
            "password": password, "password_again": password_again
        },
        type: "post",
        dataType:"text",
        success: function (response) {
            alert(response);
        }
    });
}

step 3:  HTML

<input id="register_btn" onClick="FormAjax();" type="submit" value="立即注册">

step 4:Controller

public string RegisterResult()
        {
            RegisterViewModel register = new RegisterViewModel();
            register.MobilePhone = Request.Form["phone"];
            register.VerificationCode = Request.Form["verification_code"];
            register.Password = Request.Form["password"];
            register.PasswordAgain = Request.Form["password_again"];
            if (register.MobilePhone!=""&&register.VerificationCode!=""
                &&register.Password!=""&&register.PasswordAgain!="")
            {
                return "ok";
            }
            else{
                return "false";
            }
        }