Всем доброй ночи!
Помогите пожалуйста решить проблему.
Почему при выполнении данного кода браузер не видит readyState при выполнении функции this.xmlhttp.onreadystatechange. Хотя вне этой функции он без проблем выдает значение readyState.
Как решить данную проблему?
Заранее спасибо!
function ajax() {
this.xmlhttp;
try {
this.xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
} catch (e) {
try {
this.xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} catch (E) {
this.xmlhttp = false;
}
}
if (!this.xmlhttp && typeof XMLHttpRequest!='undefined') {
this.xmlhttp = new XMLHttpRequest();
}
}
ajax.prototype.send = function() {
alert(this.xmlhttp.readyState);
this.xmlhttp.open('GET', 'ajax.php', true);
this.xmlhttp.onreadystatechange = function() {
if(this.xmlhttp.readyState == 4) {
if(this.xmlhttp.status == 200) {
alert(this.xmlhttp.responseText);
}
}
};
this.xmlhttp.send(null);
}
var my = new ajax();
my.send();