- 导入jquery
<script src="~/lib/jquery/dist/jquery-3.3.1.js" type="text/javascript"></script>
-
在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); } }); }
- HTML5中使用
<input id="register_btn" onClick="FormAjax();" type="submit" value="立即注册">
-
控制器RegisterController中使用
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!=""&®ister.VerificationCode!="" &®ister.Password!=""&®ister.PasswordAgain!="") { return "ok"; } else{ return "false"; } }