我创建了一个XMLHttpRequest来获取一个RSS feed和一个ATOM feed。 Firefox和Internet Explorer 10都适用于我。但是,使用IE10的访问者定期收到错误消息(尽管错误消息会在一两天之后恢复之前停止一段时间)。
我的常规错误捕获脚本指向与“send()”命令相同的行,并返回错误消息“完成此操作所需的数据尚不可用”。通过专门针对XMLHttpRequest的二级错误捕获器报告的其他信息将是:readyState = 4,status = 0,statusText返回空白(没有文本,没有'null',只是空白)。
有问题的网站有一个带有变音符号的域名,但我确保使用相对地址('/some.url')。
我已尝试过在网上找到的许多不同的潜在解决方案,但似乎没有解决问题。访问者的浏览器被确认使用了最新版本的javascript。
访问者可能导致此问题的原因是什么? 如何进一步确定问题的原因? 这个问题可以避免吗?
if ( window.XMLHttpRequest ) {
var xhr = new XMLHttpRequest();
}
else if ( window.ActiveXObject ) {
try {
var xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
catch( e ) {
var xhr = new ActiveXObject("Msxml2.XMLHTTP");
}
}
var feedtitle = '';
var feedno = 0;
var feedtype = '';
var feedmax = 1;
function feedcycler(n) {
feedno = n+1;
if (feedno == 2) {audrey('Forum','/forum/feed.php?mode=news','atom',10)};
if (feedno == 1) {audrey('Press','/press/feed/','rss',1)};
}
function audrey(feedtitl,feed,feedt,feedm) {
// 'feed' contains the actual url, the rest of the variables are used in 'feedme2'
feedtitle = feedtitl;
feedtype = feedt;
feedmax = feedm;
if ( window.XMLHttpRequest ) {
xhr = new XMLHttpRequest();
}
else if ( window.ActiveXObject ) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
catch( e ) {
xhr = new ActiveXObject("Msxml2.XMLHTTP");
}
}
if (xhr != null) {
xhr.open("GET", feed, true);
xhr.onerror = function (e) {
var fs = '<div class="notes"><h3>'+feedtitle+'</h3>';
fs += '<div>';
fs += 'Feed failure.'
fs += '<br/> State: ' + xhr.readyState;
fs += '<br/> Status: ' + xhr.status;
fs += '<br/> Text: ' + xhr.statusText;
fs += '</div>';
fs += '</div>';
document.getElementById('news').innerHTML += fs;
};
xhr.onload = feedme1;
xhr.send();
}
else {
var fs = '<div class="notes"><h3>'+feedtitle+'</h3>';
fs += '<div>Din webbläsare saknar AJAX-funktionalitet.</div>';
fs += '</div>';
document.getElementById('news').innerHTML += fs;
}
}
function feedme1() {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
feedme2(xhr)
}
else {
console.error(xhr.statusText);
}
}
}
function feedme2 (xhr) {
// this function contains further processing, formatting and output of the data
}