ajax表单提交
来源:互联网 发布:淘宝店怎么备案? 编辑:程序博客网 时间:2024/05/15 04:35
js代码:
<script type="text/javascript"> $('#LoginDialog').dialog({ title: '登录', width: 400, height: 200, closed: false, cache: false, modal: true, buttons: [{ iconCls:'icon-edit', text:'登录', handler: function () { $.ajax({ type: "POST", url: "/Home/LoginIn", //data:{ // name: $("#tableForm input[name=UName]").val(), // pwd: $("#tableForm input[name=UPwd]").val(), //}, data:$("#LoginInputForm").serialize(), cache: false, dataType: "json", success: function (data) { if (data.Statu == 1) { window.location = data.BackUrl; } else { alert(data.Msg); } } }); } }, { iconCls:'icon-ok', text:'注册', handler: function () { } }] }); function ok(jsonData) { $.procAjaxMsg(jsonData, function () { window.location = jsonData.BackUrl; }, function () { alert("登录失败"); }) }; </script>
登录界面
<div id="LoginDialog" style="width:420px;"> <form id="LoginInputForm" method="post" novalidate="novalidate" > <table id="tableForm"> <tr> <td>用户名:</td> <td><input class="easyui-validatebox" type="text" id="UName" name="UName" data-options="required:true,missingMessage:'请输入密码;'"/></td> </tr> <tr> <td>密码:</td> <td><input class="easyui-validatebox" type="text" id="UPwd" name="UPwd" data-options="required:true,missingMessage:'请输入密码;'"/></td> </tr> <tr> <td>验证码:</td> <td><input class="easyui-validatebox" type="text" id="Uyzm" name="Uyzm" data-options="required:true,missingMessage:'请输入验证码;'"/> <img src="/Home/CheckCode?ID=1" id="ImgCode" alt="单击可刷新" onclick="ClickRemoveChangeCode()" /> <div style="float:right; margin-top: 5px;"> <a href="javascript:void(0)" onclick="ClickRemoveChangeCode();return false;">看不清,换一张</a> </div> <input id="btn_save" type="button" value="登录" style="width: 150px" onclick="login();" /> </td> </tr> </table> </form> </div>
控制器的代码:
#region 处理登录的信息 /// <summary> /// 处理登录的信息 /// </summary> /// <returns></returns> [HttpPost] public ActionResult LoginIn() { OperateContext oc =OperateContext.CurrentContext; //string strLoginName = Request.Form["name"]; //string strLoginPwd = Request.Form["pwd"]; //将表单信息serialize序列化后提交 if (Request.Form["UName"] == null || Request.Form["UPwd"] == null) { return OperateContext.CurrentContext.PackagingAjaxMsg(AjaxStatu.err, "登录名或密码为空"); } string strLoginName = Request.Form["UName"]; string strLoginPwd = Request.Form["UPwd"]; Ou_UserInfo usr=oc._IBLLSession.IOu_UserInfoBLL.Login(strLoginName, strLoginPwd); if (usr != null) { //把登录信息保存到Session中 Session["loginUser"] = usr; //返回json信息 JsonResult ss = OperateContext.CurrentContext.PackagingAjaxMsg(AjaxStatu.ok, "登录成功", null, "/Home/Index"); return ss; } else { //返回json信息 return OperateContext.CurrentContext.PackagingAjaxMsg(AjaxStatu.err, "登录名或密码不正确", null); } } #endregion
以上是ajax提交表单,并将表单数据serialize序列化是的过程。
0 0
- Ajax表单提交实例
- Ajax表单提交实例
- Ajax表单提交实例
- ajax提交表单
- ajax提交form表单
- Ajax表单提交乱码
- ajax提交表单
- jQuery+aJax表单提交
- AJAX提交表单
- AJAX提交表单方法
- ajax提交表单
- ajax提交form表单
- AJAX提交表单数据
- ajax 提交form表单
- Jquery ajax 表单提交
- ajax提交form表单
- ajax提交form表单
- jquery ajax 提交表单
- android状态栏着色
- STM32中断优先级彻底讲解
- 走遍美洲 —— 加勒比海
- HTTP的基本介绍
- [JAVA学习笔记-66]系统吞吐量的概念
- ajax表单提交
- 初学JAVA一个星期加android studio一天弄了个简单的幼儿加法程序
- 微服务框架Finagle介绍 Part3: 在Finagle中开发基于Thrift协议的应用
- 机器学习中的数学(5)-强大的矩阵奇异值分解(SVD)及其应用
- Hololens入门之使用360度全景图作为天空盒
- git 学习
- Qt之JSON
- iTunes Connect—— 应用上架过程中App状态指南
- 1.ReactiveX - 什么是Rx,Rx的理念和优势