Ajax學習 一
<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對像
?xmlHttp.onreadystatechange = handleStateChange;?????//當請求狀態改變時調用
?xmlHttp.open("GET","simpleResponse.xml",true);????//True表請求上本質是否異步
?xmlHttp.send(null);??????//向服務器發送請求
}
function handleStateChange(){
?if(xmlHttp.readyState == 4){??????// 4、數據接收完畢,此時可以通過通過responseBody和responseText獲取完整的回應數據
??if(xmlHttp.status == 200){?????????//請求成功返回
???alert("The server replied with: " + xmlHttp.responseText);
??}
?}
}
</script>