0
我不明白爲什麼我在網上得到類型錯誤(this.req是不確定的): 如果(this.req.readyState === 4){未定義的類型,當我把我的代碼對象中的JavaScript AJAX
function RequestCORS(url) {
this.url = "http://crossorigin.me/" + url;
this.req = new XMLHttpRequest();
}
RequestCORS.prototype.send = function() {
this.req.open("GET", this.url);
this.req.onreadystatechange = function() {
if (this.req.readyState === 4) {
if (this.req.status === 200) {
console.log(this.req.responseText);
} else {
console.log("error request");
//handleError
}
}
};
this.req.send();
};
function main() {
var url = "http://www.01net.com/rss/mediaplayer/replay/";
var requete = new RequestCORS(url);
requete.send();
}
window.addEventListener("load", main);
感謝您的閱讀。
由於這是工作。 – Fitzzz