.net的ajax請(qǐng)求數(shù)據(jù)提交實(shí)例
來(lái)源:易賢網(wǎng) 閱讀:1184 次 日期:2015-02-02 13:48:52
溫馨提示:易賢網(wǎng)小編為您整理了“.net的ajax請(qǐng)求數(shù)據(jù)提交實(shí)例”,方便廣大網(wǎng)友查閱!

本文實(shí)例講述了.net的ajax請(qǐng)求數(shù)據(jù)提交實(shí)現(xiàn)方法。分享給大家供大家參考。具體如下:

復(fù)制代碼 代碼如下:<%@ page language=c# inherits=system.web.mvc.viewpage<dynamic> %>

<head runat=server>

<title>ajax請(qǐng)求</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+導(dǎo)航-->

<div class=logo_box>

<div id=logo>

<a title=ajax請(qǐng)求>ajax請(qǐng)求</a></div>

</div>

<!---->

<div class=logincon>

<div class=loginbanner>

<img src=/images/4499633_182932517000_2.jpg /></div>

<div class=loginbox>

<h2>

<span class=fl>會(huì)員登錄</span><span class=newuser>沒(méi)有賬號(hào)?<a href='<%=url.action(register,account) %>'>立即注冊(cè)</a></span></h2>

<form id=formdata>

<div class=loginform>

<div class=inputbox>

<input type=text name=user value=用戶(hù)名/手機(jī)號(hào) class=userid />

</div>

<div class=inputbox>

<input type=text value=密碼 class=textstyle />

<input type=password name=pwd class=passwordstyle none />

</div>

<div class=warn>用戶(hù)名或密碼錯(cuò)誤!</div>

<div class=remember>

<label>

<input type=checkbox name=remembered checked />

自動(dòng)登錄</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('請(qǐng)輸入密碼');

return false;

}

var data = $(#formdata).serialize();

$.post(/login/checklogininfo, data, function (ajaxobj) {

//回傳內(nèi)容{status: 1(success)/0(fail),}

if (ajaxobj.status == 0 || status == null) {

$(.warn).show().html('用戶(hù)名或密碼錯(cuò)誤!');

} else {

//登陸成功,跳轉(zhuǎn)都制定頁(yè)面

window.location = '/membercenter/index';

}

}, json);

});

});

</script>

</html>

控制器

復(fù)制代碼 代碼如下: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();

//從數(shù)據(jù)庫(kù)讀取

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:登陸成功,記錄登陸用戶(hù)信息保存登陸狀態(tài)

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;

}

}

}

}

希望本文所述對(duì)大家的.net程序設(shè)計(jì)有所幫助。

更多信息請(qǐng)查看IT技術(shù)專(zhuān)欄

更多信息請(qǐng)查看網(wǎng)絡(luò)編程
易賢網(wǎng)手機(jī)網(wǎng)站地址:.net的ajax請(qǐng)求數(shù)據(jù)提交實(shí)例
由于各方面情況的不斷調(diào)整與變化,易賢網(wǎng)提供的所有考試信息和咨詢(xún)回復(fù)僅供參考,敬請(qǐng)考生以權(quán)威部門(mén)公布的正式信息和咨詢(xún)?yōu)闇?zhǔn)!

2025國(guó)考·省考課程試聽(tīng)報(bào)名

  • 報(bào)班類(lèi)型
  • 姓名
  • 手機(jī)號(hào)
  • 驗(yàn)證碼
關(guān)于我們 | 聯(lián)系我們 | 人才招聘 | 網(wǎng)站聲明 | 網(wǎng)站幫助 | 非正式的簡(jiǎn)要咨詢(xún) | 簡(jiǎn)要咨詢(xún)須知 | 新媒體/短視頻平臺(tái) | 手機(jī)站點(diǎn) | 投訴建議
工業(yè)和信息化部備案號(hào):滇ICP備2023014141號(hào)-1 云南省教育廳備案號(hào):云教ICP備0901021 滇公網(wǎng)安備53010202001879號(hào) 人力資源服務(wù)許可證:(云)人服證字(2023)第0102001523號(hào)
云南網(wǎng)警備案專(zhuān)用圖標(biāo)
聯(lián)系電話(huà):0871-65099533/13759567129 獲取招聘考試信息及咨詢(xún)關(guān)注公眾號(hào):hfpxwx
咨詢(xún)QQ:1093837350(9:00—18:00)版權(quán)所有:易賢網(wǎng)
云南網(wǎng)警報(bào)警專(zhuān)用圖標(biāo)