哪位有Ajax 在Asp.net(c#)中即时验证用户名的源代码(要从数据库中读数据的),我是要学习的,代码简单最好,我就60分了,全给
我说到作到,
------解决方案--------------------没明白你的意思,但是我有,用ajax做登陆的代码,给你参考吧.
下面是通用js脚本:
// JScript 文件, 2006-05-15--chx
//用于ajax的公用操作
function createRequestObject() //创建XMLHttpRequest对象
{
var xmlhttp_request=null;
try{
if( window.ActiveXObject )
{
for( var i = 5; i; i-- )
{
try{
if( i == 2 )
{
xmlhttp_request = new ActiveXObject( "Microsoft.XMLHTTP " );
}
else
{
xmlhttp_request = new ActiveXObject( "Msxml2.XMLHTTP. " + i + ".0 " );
xmlhttp_request.setRequestHeader( "Content-Type ", "text/xml ");
xmlhttp_request.setRequestHeader( "Content-Type ", "GB2312 ");
}
break;
}
catch(e)
{
xmlhttp_request=null;
}
}
}
else if( window.XMLHttpRequest )
{
xmlhttp_request = new XMLHttpRequest();
if (xmlhttp_request.overrideMimeType)
{
xmlhttp_request.overrideMimeType( 'text/xml ');
//xmlhttp_request.overrideMimeType( 'GB2312 ');
}
}
}
catch(e)
{
xmlhttp_request=null;
}
return xmlhttp_request ;
}
//发送异步请求
function SendRequest(method,url,data,callback,isasyn)//callback该函数获取异步返回信息并显示,dada是字符串
{
var xmlhttp=createRequestObject();
with(xmlhttp)
{
try
{
// 加随机数防止缓存
if (url.indexOf( "? ") > 0)
{
url += "&randnum= " + Math.random();
}
else
{
url += "?randnum= " + Math.random();
}
open(method, url,isasyn);
// 设定请求编码方式
//setRequestHeader( 'Content-Type ', 'application/x-www-form-urlencoded; charset=UTF-8 ');
setRequestHeader( 'Content-Type ', 'application/x-www-form-urlencoded; charset=GB2312 ');
if(data!= " ")
{
send(data);
}
else
{
send();
}
onreadystatechange = function ()
{
if (xmlhttp.readyState == 4)//判断异步调用是否成功
{
callback(xmlhttp);
xmlhttp=null;
}
}
}
catch(e)
{
alert(e);
}
}
}
下面是实际代码:
<script type= "text/javascript " src= "../JScript/ajax.js "> </script>
<script type= "text/javascript ">