Сообщение от Dim@
|
function Ajax () {
var xmlhttp;
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
xmlhttp = false;
}
}
if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
xmlhttp = new XMLHttpRequest();
}
return xmlhttp;
}
|
Давно пора забыть уже про этот способ.
Достаточно делать так:
var ajax = window.XMLHttpRequest ? new XMLHttpRequest : new ActiveXObject("Microsoft.XMLHTTP");
ajax.open("GET", "test.xml", true);
ajax.onreadystatechange = function() {
if ( ajax.readyState == 4 ) {
var status = ( ajax.status === 1223 ) ? 204 :
( ajax.status === 0 && ( self.location || {} ).protocol == 'file:' ) ? 200 : ajax.status;
if ( status >= 200 && status < 300 || status === 304 ) {
alert( ajax.responseText ); // срабатывает
}
}
};
ajax.send( null );