怎么在asp.net中利用Ajax实现一个用户登陆功能

  介绍

这期内容当中小编将会给大家带来有关怎么在asp.net中利用Ajax实现一个用户登陆功能,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。

以用户登录为例练习Ajax的使用方法

login.html

? & lt; ! DOCTYPE  html>   & lt; html  xmlns=癶ttp://www.w3.org/1999/xhtml"比;   & lt; head>   & lt; meta  http-equiv=癈ontent-Type",内容=皌ext/html;, charset=utf-8"/比;   & lt;才能title> & lt;/title>   & lt;才能script 类型=拔谋?javascript"比;   ,,,var  obj =, createobj ();   ,   ,,,function 登录(名称,pwd)   ,,,{   ,,,,,var  urlstr =,“http://localhost: 14248/server.aspx ?用户名=?+,name  +,“和密码=?+,pwd;   ,,,,,obj.open (“get",, urlstr,,真的);   ,,,,,obj.onreadystatechange =, dowork;   ,,,,,obj.send ();   ,,,}   ,   ,,,function  dowork ()   ,,,{   ,,,,,if  (==obj.readyState  4)   ,,,,,{   ,,,,,,,if  (obj.status ==, 200)   ,,,,,,,{   ,,,,,,,,,. getelementbyid (“msg") .innerText =, obj.responseText;   ,,,,,,,}   ,,,,,}   ,,,}   ,,,//创建对象   ,,,function  createobj ()   ,,,{   ,,,,,var  xmlHttp =,空;   ,,,,,try  {   ,,,,,,,//非IE浏览器   ,,,,,,,xmlHttp =, new  XMLHttpRequest ();   ,,,,,}   ,,,,,catch  (e)   ,,,,,{,,//IE浏览器   ,,,,,,,试着{   ,,,,,,,,,xmlHttp =, new  ActiveXObject (“Msxml2.HTTP");   ,,,,,,,}   ,,,,,,,catch  (e)   ,,,,,,,{   ,,,,,,,,,xmlHttp =, new  ActiveXObject (“Microsoft.XMLHTTP");   ,,,,,,,}   ,,,,,}   ,,,,,return  xmlHttp;   ,,,}   & lt;才能/script>   & lt;/head>   & lt; body>   & lt;才能table>   ,,,& lt; tr>   ,,,,,& lt; td 对齐=癱enter", colspan=?“祝辞登录& lt;/td>   ,,,& lt;/tr>   ,,,& lt; tr>   ,,,,,& lt; td>用户名:& lt;/td>   ,,,,,& lt; td> & lt; input 类型=皌ext", id=皍sername", name=皍sername",/祝辞& lt;/td>   ,,,& lt;/tr>   ,,,& lt; tr>   ,,,,,& lt; td>密码:& lt;/td>   ,,,,,& lt; td> & lt; input 类型=皃assword", id=皃assword", name=皃assword",/祝辞& lt;/td>   ,,,& lt;/tr>   ,,,& lt; tr>   ,,,,,& lt; td 比;   ,,,,,,,& lt; input 类型=皊ubmit",价值=https://www.yisu.com/zixun/暗锹肌皁nclick="登录(. getelementbyid(“用户名”)value . getelementbyid(“密码”)value)”/>   道明>      道明>            

木豆。cs

? using 系统;   using  System.Collections.Generic;   using  System.Data;   using  System.Data.SqlClient;   using 来;   using 包含;   ,   namespace  AJAXtest   {   public 才能;class 木豆   {才能   ,,,private  string  connstr =,“服务器=acer-pc;数据库=mydatabase; user  id=sa;密码=123456“;;   ,,,public  DataTable  selectDB (string  sql)   ,,,{   ,,,,,DataTable  dt =, new  DataTable ();   ,,,,,试一试   ,,,,,{   ,,,,,,,SqlConnection  conn =, new  SqlConnection (connstr);   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null   null

怎么在asp.net中利用Ajax实现一个用户登陆功能