Ajax學(xué)習(xí) 一
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest(){
?if(window.ActiveXObject){????????????//判斷是否是IE
??xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
?}else if(window.XMLHttpRequest){
??xmlHttp = new XMLHttpRequest();
?}
}
function startRequest(){
?createXMLHttpRequest();???????? //得到XmlHttp對(duì)像
?xmlHttp.onreadystatechange = handleStateChange;?????//當(dāng)請(qǐng)求狀態(tài)改變時(shí)調(diào)用
?xmlHttp.open("GET","simpleResponse.xml",true);????//True表請(qǐng)求上本質(zhì)是否異步
?xmlHttp.send(null);??????//向服務(wù)器發(fā)送請(qǐng)求
}
function handleStateChange(){
?if(xmlHttp.readyState == 4){??????// 4、數(shù)據(jù)接收完畢,此時(shí)可以通過通過responseBody和responseText獲取完整的回應(yīng)數(shù)據(jù)
??if(xmlHttp.status == 200){?????????//請(qǐng)求成功返回
???alert("The server replied with: " + xmlHttp.responseText);
??}
?}
}
</script>
<script type="text/javascript">
var xmlHttp;
function createXMLHttpRequest(){
?if(window.ActiveXObject){????????????//判斷是否是IE
??xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
?}else if(window.XMLHttpRequest){
??xmlHttp = new XMLHttpRequest();
?}
}
function startRequest(){
?createXMLHttpRequest();???????? //得到XmlHttp對(duì)像
?xmlHttp.onreadystatechange = handleStateChange;?????//當(dāng)請(qǐng)求狀態(tài)改變時(shí)調(diào)用
?xmlHttp.open("GET","simpleResponse.xml",true);????//True表請(qǐng)求上本質(zhì)是否異步
?xmlHttp.send(null);??????//向服務(wù)器發(fā)送請(qǐng)求
}
function handleStateChange(){
?if(xmlHttp.readyState == 4){??????// 4、數(shù)據(jù)接收完畢,此時(shí)可以通過通過responseBody和responseText獲取完整的回應(yīng)數(shù)據(jù)
??if(xmlHttp.status == 200){?????????//請(qǐng)求成功返回
???alert("The server replied with: " + xmlHttp.responseText);
??}
?}
}
</script>