我的代码如下,下面那个https的地址就能读到,而http就会进入onerror
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
var response = xhr.responseText;
console.log(response);
}
};
xhr.onload = function () {
if (xhr.readyState == 4 && (xhr.status >= 200 && xhr.status < 400)) {
var response = xhr.responseText;
console.log(response);
}
};
xhr.onerror = function (e) {
var x = 0
};
xhr.ontimeout = function () {
var x = 0
};
//xhr.open("GET", "https://httpbin.org/get?show_env=1", true);
xhr.open("GET", "http://www.w3school.com.cn/example/xmle/note.xml", true);
xhr.send();