創(chuàng)建XMLHTTP對象,區(qū)別IE,Mozilla瀏覽器
復制代碼 代碼如下:
function getRequest() {
http_request = false;
if (window.XMLHttpRequest) {
//對于Mozilla﹑Netscape﹑Safari等瀏覽器,創(chuàng)建XMLHttpRequest
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType) {
//如果服務器響應的header不是text/xml,可以調(diào)用其它方法修改該header
http_request.overrideMimeType('text/xml');
}
} else if (window.ActiveXObject) {
// 對于Internet Explorer瀏覽器,創(chuàng)建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的區(qū)域
}
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的區(qū)域
}
else {
requestdoc = http_request.status;
}
}
return requestdoc;
}