本文实例讲述了.NET的Ajax请求数据提交实现方法。分享给大家供大家参考。具体如下:
<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage<dynamic>" %> <head runat="server"> <title>ajax请求</title> <link type="text/css" rel="stylesheet" href="/Content/style.css" /> <script type="text/javascript" src="/Scripts/jquery-1.8.3.min.js"></script> <script type="text/javascript" src="/Scripts/js.js"></script> </head> <body> <!--顶部+logo+导航--> <div class="logo_box"> <div id="logo"> <a title="ajax请求">ajax请求</a></div> </div> <!----> <div class="loginCon"> <div class="loginBanner"> <img src="/Images/4499633_182932517000_2.jpg" /></div> <div class="loginBox"> <h2> <span class="fl">会员登录</span><span class="newUser">没有账号?<a href='<%=Url.Action("Register","Account") %>'>立即注册</a></span></h2> <form id="formData"> <div class="loginForm"> <div class="inputBox"> <input type="text" name="user" value="用户名/手机号" class="userId" /> </div> <div class="inputBox"> <input type="text" value="密码" class="textStyle" /> <input type="password" name="pwd" class="passwordStyle none" /> </div> <div class="warn">用户名或密码错误!</div> <div class="remember"> <label> <input type="checkbox" name="remembered" checked /> 自动登录</label> <a class="forget" href='<%=Url.Action("ResetPwd","Login") %>' >忘记密码?</a> </div> <input class="loginBtn" type="button" value="登录"/> </div> </form> </div> </div> </body> <script type="text/javascript"> $(function () { $('.userId,.passwordStyle').on('keyup', function (e) { if (e.keyCode == 13) { $('.loginBtn').trigger('click'); } }); $('.loginBtn').on('click', function () { $(".warn").hide(); var pwd = $('.passwordStyle').val(); if (pwd == '') { $(".warn").show().html('请输入密码'); return false; } var data = $("#formData").serialize(); $.post("/login/checkLoginInfo", data, function (ajaxObj) { //回传内容{status: 1(success)/0(fail),} if (ajaxObj.status == 0 || status == null) { $(".warn").show().html('用户名或密码错误!'); } else { //登陆成功,跳转都制定页面 window.location = '/memberCenter/index'; } }, "json"); }); }); </script> </html>
控制器
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.Mvc; using System.Text; namespace bigtree.Controllers { using bigtree.Models; using bigtree.Model; using bigtree.lib; using System.Net.Mail; using System.Text.RegularExpressions; public class LoginController : Controller { public ActionResult Index() { return View(); } /// <summary> /// 检查登陆 /// </summary> /// <param name="f"></param> /// <returns></returns> [HttpPost] public ActionResult CheckLoginInfo(FormCollection f) { try { //post: user , pwd ,remembered string user = f["user"].Trim(); string pwd = f["pwd"].Trim(); string remembered = f["remembered"].Trim(); JsonResult res = new JsonResult(); if (string.IsNullOrEmpty(user) || string.IsNullOrEmpty(pwd)) { res.Data = new { status = 0 }; } //MD5加密后的密码 pwd = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pwd, "md5").ToLower(); //从数据库读取 Common.WebUser account = MemberInfoService.GetMemberIdForCheck(user, pwd); if (account == null) { res.Data = new { status = 0 }; } else { //{status: 1(success)/0(fail),} res.Data = new { status = 1 }; //todo:登陆成功,记录登陆用户信息保存登陆状态 FunSession.SetSession(account); //是否记住登录 if (remembered == "on") { HttpCookie cookie = new HttpCookie("LoginInfo", account.Id.ToString()); //3天有效 cookie.Expires.AddDays(3); Response.Cookies.Add(cookie); } else { HttpCookie cookie = new HttpCookie(account.Id.ToString(), account.Id.ToString()); //使失效 cookie.Expires.AddYears(-1); Response.Cookies.Add(cookie); } } return res; } catch (Exception ex) { throw ex.InnerException; } } } }
希望本文所述对大家的.NET程序设计有所帮助。
当我在symfony4中提交json http post请求时,requesthandling不会提交我的表单。 我尝试将“方法”选项设置为要发布的表单,但似乎没有帮助。我将application/json头用于Content-type和Accept。 表格: 控制器: 还有我的http帖子: 标头:内容类型:应用程序/json接受:应用程序/json 正文:{“用户名”:“dunglas”} 我
本文向大家介绍AJAX提交表单数据实例分析,包括了AJAX提交表单数据实例分析的使用技巧和注意事项,需要的朋友参考一下 本文实例讲述了AJAX提交表单数据的方法。分享给大家供大家参考。具体如下: 遍历表单各元素,将参数值组织成JSON格式 这里对CheckBox复选框做了特殊处理,后台接收到的该值为所有复选框值用逗号的拼接 AJAX的调用: 谈到服务器端返回的JSON格式数据,支持如下格式 前端调
Ajax 是一种不需要刷新页面就可以与服务器交换数据的方法。 关于 Ajax 相关的知识请参考 jQuery-Ajax、jQuery-AJAX - W3School 及 Ajax 教程 一、jQuery 中 Ajax 相关的函数 在 jQuery 中,有三种 Ajax 相关的方法,分别是:ajax、get、post。 1、jQuery.ajax 统一的发送 Ajax 请求函数,简单的使用示例如下:
问题内容: 我刚刚从jQuery 1.3.2更新到1.4.3,并且在发出AJAX DELETE请求时看到了一些新行为。由于某种原因,在我的参数中传递的数据没有发送到服务器。例如: 最终向发送了DELETE请求,没有其他数据。但是,这种类型的调用可以很好地传递参数: 有没有其他人看到过类似的行为?有没有理由不再起作用(即:是设计使然,还是错误)?关于如何使其运作的任何建议? 此外,如果有人想知道为什
问题内容: 我正在发送带有POST参数的AJAX请求(没有JQuery)。有什么功能可以清除&等字符吗? 问题答案: 您实际上不需要在现代浏览器中执行此操作: 如您所见,您可以将一个对象传递给该方法并将其发送给该方法,而您根本不需要对POST正文(或GET url)中的URI组件进行编码或弄乱。 您当然也可以发送表格数据
本文向大家介绍ajax请求json数据案例详解,包括了ajax请求json数据案例详解的使用技巧和注意事项,需要的朋友参考一下 今天有这样一个需求,点击六个大洲,出现对应的一些请求信息,展示在下面,请求请求过后,第二次点击就无需请求。 如图所示:点击北美洲下面出现请求的一些数据 html代码结构: css样式: json格式: js代码: