一个js的问题 急急
在写一个简单的验证的时候 需要判断用户名是否存在 我在另一个页面写了一个验证方法 javascript如何才能从这个页面传递参数过去让另个页面的方法获取参数进行判断 并返回结果 显示呢!
------解决方案--------------------register.htm
<!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>
<title> 无标题页 </title>
<script type= "text/javascript ">
function gethttprequest(){
var xmlhttp_request = false;
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 = false;
}
}
}else if( window.XMLHttpRequest ){
xmlhttp_request = new XMLHttpRequest();
if (xmlhttp_request.overrideMimeType) {
xmlhttp_request.overrideMimeType( 'text/xml ');
}
}
}
catch(e){
xmlhttp_request = false;
}
return xmlhttp_request ;
}
function check(){
var xmlhttp=gethttprequest();
var url= "check.aspx?username= "+document.getElementById( 'Text1 ').value;
xmlhttp.Open( "get ",url,false);
xmlhttp.send(null);
document.getElementById( 'div1 ').innerHTML=xmlhttp.responsetext;
}
</script>
</head>
<body>
<input id= "Text1 " type= "text " /> <input id= "Button1 " onclick= "check() " type= "button " value= "button " />
<div style= "width: 100px; height: 100px " id= "div1 ">
</div>
</body>
</html>
check.aspx.cs
SqlConnection conn = new SqlConnection( "uid=sa;pwd=;database=tu;server= ");
string name = Request[ "username "].Replace( " ' ", " ").Trim();
string sql = "select username from userinfo where username= ' " + name + " ' ";
SqlCommand cmd = new SqlCommand(sql, conn);
conn.Open();
SqlDataReader sdr = cmd.ExecuteReader();
if (sdr.Read())
{
Response.Write( "该用户名已经有人使用,请重新选择! ");
}
else
Response.Write( "该用户名可以使用! ");
sdr.Close();
cmd.Dispose();
conn.Close();