// 1、創建 XHR對象(IE6- 為ActiveX對象)
// 2、連接及發送請求
// 3、回調處理
function createXMLHttpRequest() {
var xhr;
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
if (xhr.overrideMimeType)
xhr.overrideMimeType('text/xml');
} else if (window.ActiveXObject) {
xhr = new ActiveXObject('Microsoft.XMLHTTP');
}
return xhr;
}
var xhr = createXMLHttpRequest();
if (xhr != null) {
xhr.open("get", url, true);
xhr.send(null);
xhr.onreadystatechange = function () {
// readyState 五種狀態
// 0 - (未初始化)調用了open()方法,未調用send()方法
// 1 - (載入)send()方法,正在發送請求
// 2 - (載入完成)send()方法執行完成,已經接收到全部響應內容
// 3 - (交互)正在解析響應內容
// 4 - (完成)響應內容解析完成
if (xhr.readyState == 4) {
// status:http狀態碼
if (xhr.status >= 200 && xhr.status < 300) {
} else {
}
}
}
}