asp.net中手写ajax

来源:互联网 发布:php鸟哥是谁 编辑:程序博客网 时间:2024/05/16 10:12
<html>
<head>
<title>AjaxTest</title>
<script>
var xmlHttp;
function createXMLHttpRequest()
{
if(window.ActiveXObject)
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
} else if(window.XMLHttpRequest)
{
xmlHttp = new XMLHttpRequest();
}
}

function startRequest()
{
createXMLHttpRequest();
try {
var username=document.getElementById("<%=text1.ClientID %>").value;
xmlHttp.onreadystatechange = handleStateChange;
xmlHttp.open("GET", "validname.aspx?username="+username, true);
xmlHttp.send(null);
} catch(exception) {
alert("xmlHttp Fail");
}
}

function handleStateChange()
{
if(xmlHttp.readyState == 4)
{
if (xmlHttp.status == 200 || xmlHttp.status == 0)
{
var param = xmlHttp.responseText; document.getElementById("msg").innerHTML=param;
}
}
}
</script>
</head>
<body>
<div>

<input type="type" id="text1" /><span id="msg"></span><br> <input type="button" value="Test" onclick="startRequest();" /> </div></body></html>

 

 

public void Page_Load()
{
string userName=Request.QueryString["username"];
if(iExists(userName))
{ Response.Write("用户名存在");
}
else
{
Response.Write("用户名可用");
} Response.End();
}
public bool iExists(string username){.....}
原创粉丝点击