欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Jquery+WebService 校驗(yàn)賬號(hào)是否已被注冊(cè)的代碼

 更新時(shí)間:2010年07月12日 15:12:30   作者:  
在Javascirpt代碼中,調(diào)用Jquery的方法$.Ajax(function)實(shí)現(xiàn)Ajax,傳遞賬號(hào)信息給Web服務(wù),Web服務(wù)再調(diào)用數(shù)據(jù)庫(kù)操作類(lèi)查詢(xún)數(shù)據(jù)庫(kù),并返回?cái)?shù)據(jù)給前臺(tái)頁(yè)面。
詳細(xì)代碼如下:
Default.aspx
復(fù)制代碼 代碼如下:

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Default.aspx.cs" Inherits="Ajax_XML._Default" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title></title>
<script type="text/javascript" src="jquery-1.3.2-vsdoc2.js" language="javascript"></script>
<script type="text/javascript" language="javascript">
$(function() {
$("#<%=UserID.ClientID%>").keyup(
function() {
$.ajax({
type: "POST",
contentType: "application/json",
dataType: "json",
url: "WebService1.asmx/UserIsExist",
data: "{UserID:'" + $("#<%=UserID.ClientID%>").val() + "'}",
success: function(result) {
if (result.d == "true")
$("#<%=IsExist.ClientID%>").text("Yes");  //賬號(hào)已存在
else
$("#<%=IsExist.ClientID%>").text("No");  
}
});
}
);
})
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<table style="width:100%;">
<tr>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
<asp:TextBox ID="UserID" runat="server"></asp:TextBox>
<asp:Label ID="IsExist" runat="server" Visible="true"></asp:Label>
</td>
<td>
&nbsp;</td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
<td>
&nbsp;</td>
</tr>
</table>
</div>
</form>
</body>
</html>

WebService1.asmx.cs
復(fù)制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Text;
using DAL;
namespace Ajax_XML
{
/// <summary>
/// WebService1 的摘要說(shuō)明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.ComponentModel.ToolboxItem(false)]
// 若要允許使用 ASP.NET AJAX 從腳本中調(diào)用此 Web 服務(wù),請(qǐng)取消對(duì)下行的注釋。
[System.Web.Script.Services.ScriptService]
public class WebService1 : System.Web.Services.WebService
{
[WebMethod]
public string HelloWorld()
{
return "Hello,World!";
}
[WebMethod]
public string UserIsExist(string UserID)
{
string sql = string.Format("select * from Customers where FirstName='" + UserID+"'");
using (SqlDataReader dr = SqlHelper.ExecuteSql(sql))
{
if (dr.Read())
return "false";
else
return "true";
}
}
}
}

SqlHelper.cs
復(fù)制代碼 代碼如下:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace DAL
{
/// <summary>
/// 數(shù)據(jù)庫(kù)操作類(lèi)
/// </summary>
public class SqlHelper
{
private static SqlConnection conn;
private static SqlCommand comm;
private static SqlDataReader dr;
/// <summary>
/// 打開(kāi)數(shù)據(jù)庫(kù)連接
/// </summary>
public static void ConnOpen()
{
try
{
conn = new SqlConnection(ConfigurationManager.ConnectionStrings["BBS"].ConnectionString);
conn.Open();
}
catch (Exception e)
{
Console.WriteLine( e.Message);
}
}
/// <summary>
/// 關(guān)閉數(shù)據(jù)庫(kù)連接,釋放資源
/// </summary>
public static void ConnClose()
{
if (conn != null)
{
conn.Close();
}
if (comm != null)
{
comm.Dispose();
}
}
public static SqlDataReader ExecuteSql(string sql)
{
SqlHelper.ConnOpen();
comm = new SqlCommand(sql, conn);
try
{
dr = comm.ExecuteReader();
return dr;
}
catch (Exception e)
{
throw e;
}
}
}
}

相關(guān)文章

  • 用jQuery實(shí)現(xiàn)可輸入多選下拉組合框?qū)嵗a

    用jQuery實(shí)現(xiàn)可輸入多選下拉組合框?qū)嵗a

    這篇文章主要介紹了用jquery實(shí)現(xiàn)可輸入多選下拉組合框的實(shí)例代碼,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友參考下
    2017-01-01
  • 基于jQuery傾斜打開(kāi)側(cè)邊欄菜單特效代碼

    基于jQuery傾斜打開(kāi)側(cè)邊欄菜單特效代碼

    基于jQuery多重圖片無(wú)限循環(huán)動(dòng)畫(huà)效果,本文給大家分享基于jQuery傾斜打開(kāi)側(cè)邊欄菜單特效代碼,感興趣的朋友可以參考下
    2015-09-09
  • jQuery UI插件實(shí)現(xiàn)百度提詞器效果

    jQuery UI插件實(shí)現(xiàn)百度提詞器效果

    這篇文章主要介紹了jQuery UI插件實(shí)現(xiàn)百度提詞器效果,每個(gè)輸入框中有相應(yīng)的文字提示,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2016-11-11
  • jQuery Ajax 全局調(diào)用封裝實(shí)例代碼詳解

    jQuery Ajax 全局調(diào)用封裝實(shí)例代碼詳解

    這篇文章主要介紹了jQuery Ajax 全局調(diào)用封裝實(shí)例代碼詳解的相關(guān)資料,非常不錯(cuò)具有參考借鑒價(jià)值,需要的朋友可以參考下
    2016-06-06
  • 基于EasyUI的基礎(chǔ)之上實(shí)現(xiàn)樹(shù)形功能菜單

    基于EasyUI的基礎(chǔ)之上實(shí)現(xiàn)樹(shù)形功能菜單

    這篇文章主要介紹了基于EasyUI的基礎(chǔ)之上實(shí)現(xiàn)樹(shù)形功能菜單,非常不錯(cuò),具有參考借鑒價(jià)值,需要的朋友可以參考下
    2017-06-06
  • jQuery實(shí)現(xiàn)在新增加的元素上添加事件方法案例分析

    jQuery實(shí)現(xiàn)在新增加的元素上添加事件方法案例分析

    這篇文章主要介紹了jQuery實(shí)現(xiàn)在新增加的元素上添加事件方法,結(jié)合具體實(shí)例形式分析了jQuery針對(duì)新增加的元素添加事件的實(shí)現(xiàn)技巧與注意事項(xiàng),需要的朋友可以參考下
    2017-02-02
  • Jquery利用mouseenter和mouseleave實(shí)現(xiàn)鼠標(biāo)經(jīng)過(guò)彈出層且可以點(diǎn)擊

    Jquery利用mouseenter和mouseleave實(shí)現(xiàn)鼠標(biāo)經(jīng)過(guò)彈出層且可以點(diǎn)擊

    這篇文章主要介紹了Jquery利用mouseenter和mouseleave實(shí)現(xiàn)鼠標(biāo)經(jīng)過(guò)彈出層且可以點(diǎn)擊。需要的朋友可以過(guò)來(lái)參考下,希望對(duì)大家有所幫助
    2014-02-02
  • 最新評(píng)論