0
隨着代碼下面,我得到錯誤:AJAX對象IE 8錯誤
消息:未實現。 Line: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,谷歌Chrome和Opera的作品。 謝謝。
我不明白它......錯誤指向Ajax構造函數,而且我確實有這種方法波紋管...謝謝。 – thom 2011-03-30 18:09:20
您是否看到我重命名了一個變量? – epascarello 2011-03-30 18:16:26
對不起,參數...我要去嘗試 – thom 2011-03-30 18:18:58