jquery.form.js 异步提交表单
Posted 心以不防
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了jquery.form.js 异步提交表单相关的知识,希望对你有一定的参考价值。
html
<form id="insertForm" method="post" class="form-horizontal"> <div class="form-group" id="customerName"> <label class="col-sm-2 control-label"><font style=\'color:red;\'>*</font>姓名</label> <div class="col-sm-10"><input id="name" type="text" class="form-control" name="Name"></div> </div> <div class="hr-line-dashed"></div> <div class="form-group"> <label class="col-sm-2 control-label"><font style=\'color:red;\'>*</font>性别</label> <div class="col-sm-10"> <select id="sex" class="input-md form-control input-s-sm inline" name="Sex"> <option value="true">女</option> <option value="false">男</option> </select> </div> </div> <div class="hr-line-dashed"></div> <div class="form-group"> <label class="col-sm-2 control-label">年龄</label> <div class="col-sm-10"><input id="age" type="text" class="form-control" name="Age"></div> </div> <div class="hr-line-dashed"></div> <div class="form-group"> <label class="col-sm-2 control-label">电话</label> <div class="col-sm-10"><input id="tel" type="text" class="form-control" name="Tel"></div> </div> </form>
JS
var token = $("input[name = \'__RequestVerificationToken\']").val(); //防护CSRF
$("#insertForm").ajaxSubmit({ url: "/Home/InsertInfo", type: \'post\', dataType: \'json\', data: { "__RequestVerificationToken": token }, beforeSubmit: function () { alert("beforeSubmit") }, success: function (result) { alert("success") } });
Entity
public class User { public int ID { get; set; } public string Name { get; set; } public bool Sex { get; set; } public decimal Age { get; set; } public string Tel { get; set; } public DateTime? ModifyTime { get; set; } }
Controll
[ValidateAntiForgeryToken] public void InsertInfo(User user) { using (IDbConnection conn = DapperService.mysqlConnection()) { } }
截图
以上是关于jquery.form.js 异步提交表单的主要内容,如果未能解决你的问题,请参考以下文章