asp.net 中ajax验证用户名是否重复
这是js部分
function createXMLHttpRequest()
{
if(window.XMLHttpRequest) return new XMLHttpRequest();
try{return new ActiveXObject('MSXML2.XMLHTTP.4.0');}
catch(e){try{return new ActiveXObject('MSXML2.XMLHTTP.3.0');}
catch(e){try{return new ActiveXObject('MSXML2.XMLHTTP.2.6');}
catch(e){try{return new ActiveXObject('MSXML2.XMLHTTP');}
catch(e){try{return new ActiveXObject('Microsoft.XMLHTTP');}
catch(e){return null;}}}}}
} 
function checktbxDescription()
{
//需要验证的字段
var tbxDescription=document.getElementById("tbxDescription").value;
chkXML = createXMLHttpRequest();
if(chkXML==null){top.MessageBox.show("info","你的浏览器不支持XmlHttpRequest,请更新!",null,null);return false;}
chkXML.open("GET","http://www.cnblogs.com/Ajax/AjaxChkDocDescription.ashx?Name=" + tbxDescription,true);
chkXML.onreadystatechange = function()
{
if(chkXML.readyState == 4)
{
if(chkXML.status == 200)
{
if(chkXML.responseText == "1")
{
alert("[温馨提示]该名称已存在,请重新输入!");
document.getElementById("tbxDescription").select();
return false;
}
}
}
}
chkXML.send(null);
return true;
} 
using System;
using System.Data;
using System.Web;
using System.Collections;
using System.Web.Services;
using System.Web.Services.Protocols;
namespace HCOA.Net.OAModule.Ajax
{
/// <summary>
/// $codebehindclassname$ 的摘要说明
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class AjaxChkDocDescription : IHttpHandler
{
public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "text/plain";
string description = context.Request.QueryString["Description"];
BLL.m_doc_kind bmdockind = new BLL.m_doc_kind();
DataSet ds = bmdockind.GetList("description='" + description+"'");
if (ds.Tables[0].Rows.Count > 0)
context.Response.Write("1");
else
context.Response.Write("0");
}
public bool IsReusable
{
get
{
return false;
}
}
}
}


浙公网安备 33010602011771号