这是个简单例子:
// 声明XMLHttpRequest对象
var xmlhttp
function CreateObject
{
(window.XMLHttpRequest)
{
xmlhttp= XMLHttpRequest;//Mozilla浏览器
}
(window.ActiveXObject)
{
try
{
xmlhttp= ActiveXObject(\"Msxml2.XMLHTTP\");//IE老版本
}
catch(e)
{}
try
{
xmlhttp= ActiveXObject(\"Microsoft.XMLHTTP\");//IE新版本
}
catch(e)
{}
(!xmlhttp)
{
window.alert(\"不能创建XMLHttpRequest对象!\");
false;//终止执行
}
}
}
function CheckName(UserName)
{
CreateObject;//创建XMLHttpRequest对象
var url=\"Dispost.aspx?Name=\"+UserName+\"&Event=Check\";
xmlhttp.open(\"POST\",url,true);
xmlhttp.onreadystatechange=CheckUserName; [Page]
xmlhttp.send(null);
}
function $$(id)
{
document.getElementById(id);
}
function CheckUserName
{
(xmlhttp.readystate4)//判断对象状态-----是否交互完成比如 :发送请求
{
(xmlhttp.status200)//信息成功返回开始处理信息---是否和数据库交互完成
{
(xmlhttp.responseText\"90\")//responseText接受服务器返回信息
{
$$(\"img\").innerHTML=\"<img src=images/true.g>\";
$$(\"BtnReg\").disabled=true;
}
{
$$(\"img\").innerHTML=\"<img src=images/false.g>\";
$$(\"BtnReg\").disabled=false;
}
}
}
}
对象:onreadystatechange
readyState
Status
responseText
responseXML
思路方法:open
send www.zxbc.cn
最新评论