XMLHttpRequest of ajax
2024-09-01 08:29:58
供稿:网友
调用 function(Url) {
var XML = new XMLHttpRequest();
XML.onreadystatechange = function() {
if (XML.readyState == 4)
{
if (XML.status == 200)
{
//XML.responseText
}
else
{
//XML.statusText
}
}
else
{
//数据加载中...
}
};
XML.open("GET",Url);
XML.send(null);
};定义XMLHttpRequest 适应不同的浏览器 // IE support
if (window.ActiveXObject && !window.XMLHttpRequest)
{
window.XMLHttpRequest = function()
{
var msxmls = new Array('Msxml2.XMLHTTP.5.0','Msxml2.XMLHTTP.4.0','Msxml2.XMLHTTP.3.0','Msxml2.XMLHTTP','Microsoft.XMLHTTP');
for (var i = 0; i < msxmls.length; i++)
{
try
{
return new ActiveXObject(msxmls[i]);
}
catch (e)
{
}
}
return null;
};
}
// Opera support
if (window.opera && !window.XMLHttpRequest)
{
window.XMLHttpRequest = function()
{
this.readyState = 0; // 0=uninitialized,1=loading,2=loaded,3=interactive,4=complete
this.status = 0; // HTTP status codes
this.statusText = '';
this._headers = [];
this._aborted = false;
this._async = true;
this._defaultCharset = 'ISO-8859-1';
this._getCharset = function()
{
var charset = _defaultCharset;
var contentType = this.getResponseHeader('Content-type').toUpperCase();
val = contentType.indexOf('CHARSET=');
if (val != -1)
{
charset = contentType.substring(val);
}