如何在.NET中使用Ajax请求提交数据-创新互联

如何在.NET中使用Ajax请求提交数据?相信很多没有经验的人对此束手无策,为此本文总结了问题出现的原因和解决方法,通过这篇文章希望你能解决这个问题。

成都网站建设哪家好,找创新互联!专注于网页设计、重庆网站建设、微信开发、微信平台小程序开发、集团成都企业网站定制等服务项目。核心团队均拥有互联网行业多年经验,服务众多知名企业客户;涵盖的客户类型包括:水处理设备等众多领域,积累了大量丰富的经验,同时也获得了客户的一致认可!

具体如下:


<%@ Page Language="C#" Inherits="System.Web.Mvc.ViewPage" %>


 
 
    ajax请求 
     
     
     
 
 
     
   

 
         
   
 
     
   
 
       
 
           
 
       
 
           

 
                会员登录没有账号?'>立即注册

 
 
           
 
           
 
               
 
                     
               
 
               
 
                     
                     
               
 
               
用户名或密码错误!
 
               
 
                     
                    ' >忘记密码? 
               
 
                 
           
 
           
 
       
 
   
 
 
 

控制器


复制代码 代码如下:

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(); 
        } 
        ///

 
        /// 检查登陆 
        ///
 
        ///  
        ///  
        [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中使用Ajax请求提交数据的方法了吗?如果还想学到更多技能或想了解更多相关内容,欢迎关注创新互联行业资讯频道,感谢各位的阅读!


文章名称:如何在.NET中使用Ajax请求提交数据-创新互联
URL分享:http://myzitong.com/article/egjcd.html