我在Edge中使用XMLHttpRequest,但是得到这个。我使用各种请求,例如:Fetch,XMLHttpRequest,superagen,它们都是一样的XMLHttpRequst failed
它可以在Chrome / ie / etc。但仅在Edge中失败。
奇怪的是,当我打开Fiddler4时,请求成功,一切都显示完美。
var xhr = new XMLHttpRequest();
let uri = 'http://' + '10.13.40.70' + ':' + '55666' + '/connect' + '?ts=' + new Date().getTime() + "&webconnectid=" + '0037d82f5c17830b437188e33f91a5c3' + "&webconnecttype=" + 'WEBCONNECTTYPE_FIRST' ;
console.log(uri)
xhr.open('GET', uri);
xhr.setRequestHeader('Cache-Control', 'max-age=0');
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.setRequestHeader('Access-Control-Allow-Credentials', 'true');
xhr.setRequestHeader('If-Modified-Since', 'no-cache');
xhr.send();
xhr.onreadystatechange = function(){
console.log("readyState:" + this.readyState)
}
xhr.onload = function() {
console.log(xhr)
if (xhr.status != 200) { // analyze HTTP status of the response
alert(`Error ${xhr.status}: ${xhr.statusText}`); // e.g. 404: Not Found
} else { // show the result
alert(`Done, got ${xhr.response.length} bytes`); // responseText is the server
}
};
xhr.onerror = function(){
console.log(xhr)
alert("failed !")
}
我想知道为什么会这样。
对不起,这是我的代码:
var xhr = new XMLHttpRequest();
let uri = 'http://' + '10.13.40.70' + ':' + '55666' + '/connect' + '?ts=' + new Date().getTime() + "&webconnectid=" + '0037d82f5c17830b437188e33f91a5c3' + "&webconnecttype=" + 'WEBCONNECTTYPE_FIRST' ;
console.log(uri)
xhr.open('GET', uri);
xhr.setRequestHeader('Cache-Control', 'max-age=0');
xhr.setRequestHeader('Access-Control-Allow-Origin', '*');
xhr.setRequestHeader('Access-Control-Allow-Credentials', 'true');
xhr.setRequestHeader('If-Modified-Since', 'no-cache');
xhr.send();
xhr.onreadystatechange = function(){
console.log("readyState:" + this.readyState)
}
xhr.onload = function() {
console.log(xhr)
if (xhr.status != 200) { // analyze HTTP status of the response
alert(`Error ${xhr.status}: ${xhr.statusText}`); // e.g. 404: Not Found
} else { // show the result
alert(`Done, got ${xhr.response.length} bytes`); // responseText is the server
}
};
xhr.onerror = function(){
console.log(xhr)
alert("failed !")
}