AJAX объект IE 8 ошибка - PullRequest
       6

AJAX объект IE 8 ошибка

0 голосов
/ 30 марта 2011

С кодом ниже я получаю ошибку:

Сообщение: не реализовано.Строка: this.xmlHttpRequestObject.onreadystatechange = onreadystatechange;

ajax.js

function Ajax(url, method, onreadystatechange, asynchronous) {
    this.xmlHttpRequestObject = new XMLHttpRequest();
    this.method = method;
    this.url = url;
    this.asynchronous = asynchronous === undefined ? true : asynchronous;
    this.xmlHttpRequestObject.onreadystatechange = onreadystatechange;
}

Ajax.prototype.send = function () {
    this.xmlHttpRequestObject.open(this.method, this.url, this.asynchronous);
    this.xmlHttpRequestObject.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
    this.xmlHttpRequestObject.send();

    return this;
};

Ajax.prototype.onreadystatechange = function (onreadystatechange) {
    this.xmlHttpRequestObject.onreadystatechange = onreadystatechange;

    return this;
};

Ajax.prototype.onloadstart = function (onloadstart) {
    this.xmlHttpRequestObject.onloadstart = onloadstart;

    return this;
};

Ajax.prototype.onload = function (onload) {
    this.xmlHttpRequestObject.onload = onload;

    return this;
};

scripts.js

function loadPage(page) {
    var ajax = new Ajax(page, 'GET');

    ajax.onloadstart(function () {
        var div = document.createElement('div'),
            p = document.createElement('p'),
            img = document.createElement('img'),
            section = document.querySelector('section');

        removeChildrenElements(section);
        section.style.minHeight = '230px';

        div.setAttribute('id', 'loading');

        img.setAttribute('src', 'media/images/loading.gif');
        img.setAttribute('alt', 'Carregando');

        p.appendChild(document.createTextNode('Carregando. Por favor, aguarde ...'));

        div.appendChild(p);
        div.appendChild(img);

        document.querySelector('section').appendChild(div);
    });

    ajax.onreadystatechange(function (event) {
        if (this.readyState === 4 && this.status === 200) {
            document.querySelector('section').innerHTML = this.responseText;
        } else if (this.status === 404) {
            this.abort();
            document.location = 'http://www.mydomain.com.br/404';
        }
    });

    ajax.send();
}

Этот скрипт работает в Firefox 4, Google Chrome иOpera.Спасибо.

1 Ответ

0 голосов
/ 30 марта 2011

Может быть конфликт с объектами окна / документа. Попробуйте изменить код на

Ajax.prototype.onreadystatechange = function (readystatechange) {
    this.xmlHttpRequestObject.onreadystatechange = readystatechange;
    return this;
};
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...