ajax|函數
建立XMLHTTP對象,區別IE,Mozilla瀏覽器
[複製此代碼]CODE: 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
[複製此代碼]CODE: 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
[複製此代碼]CODE: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;
}