創建XMLHTTP對象,區別IE,Mozilla浏覽器
復制代碼 代碼如下: function getRequest() {
http_request = false;
if (window.XMLHttpRequest) {
//對於Mozilla﹑Netscape﹑Safari等浏覽器,創建XMLHttpRequest
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
//如果服務器響應的header不是text/xml,可以調用其它方法修改該header
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) {
// 對於Internet Explorer浏覽器,創建XMLHttpRequest
try {
http_request = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
http_request = new ActiveXObject("Microsoft.XMLHTTP");
} catch (e) {}
}
}
return http_request;
} //
獲得Url 的responseText
復制代碼 代碼如下: function getResponseText(url)
{
http_request=getRequest();
http_request.open('GET', url, false);
http_request.send(null);
if (http_request.readyState == 4)
{
// 收到完整的服務器響應
if (http_request.status == 200) {
//HTTP服務器響應的值OK
requestdoc = http_request.responseText;
//將服務器返回的字符串寫到頁面中ID為message的區域
}
else {
requestdoc = http_request.status;
}
}
return requestdoc;
} //
獲得Url 的responseXML 復制代碼 代碼如下:function getResponseText(url)
{
http_request=getRequest();
http_request.open('GET', url, false);
http_request.send(null);
if (http_request.readyState == 4)
{
// 收到完整的服務器響應
if (http_request.status == 200) {
//HTTP服務器響應的值OK
requestdoc = http_request.responseXML;
//將服務器返回的字符串寫到頁面中ID為message的區域
}
else {
requestdoc = http_request.status;
}
}
return requestdoc;
}