Posted on 2007-04-23 19:10
吳濤濤 閱讀(391)
評論(0) 編輯 收藏
<!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>
<script type="text/javascript">
/* Create a new XMLHttpRequest object to talk to the Web server */
function getbw()
{
var xmlhttp;
try {
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
} catch (oc) {
xmlhttp=null;
}
}
if(!xmlhttp && typeof XMLHttpRequest != "undefined")
xmlhttp = new XMLHttpRequest();
return xmlhttp;
}
function IDRequest(n) {
xmlhttp=getbw();
//定義收到服務(wù)器的響應(yīng)后需要執(zhí)行的JavaScript函數(shù)
url=n+document.getElementById('163id').value;//定義網(wǎng)址參數(shù)
alert(url);
xmlhttp.open("GET",url, true);
xmlhttp.send(null);
//xmlhttp_request=getXMLRequester();//調(diào)用創(chuàng)建XMLHttpRequest的函數(shù)
xmlhttp.onreadystatechange = doContents;//調(diào)用doContents函數(shù)
}
function doContents() {
if (xmlhttp.readyState == 4) {// 收到完整的服務(wù)器響應(yīng)
if (xmlhttp.status == 200) {//HTTP服務(wù)器響應(yīng)的值OK
document.getElementById('message').innerHTML = xmlhttp.responseText;//將服務(wù)器返回的字符串寫到頁面中ID為message的區(qū)域
} else {
alert(xmlhttp.status);
}
}
}
</script>
</head>
<body>
<input type="text" id="163id" />
<input type="button" value="校驗" onclick="IDRequest('check.php?userid=')" />
<div id="message"></div>
</body>
</html>