0
私は奇妙な問題があります。xhr.responseXMLはChromeとIEで異なる結果です
XMLファイルをXMLHttpRequest()
からロードしてアクセスしたいとします。 ChromeとFirefoxで正しいXMLドキュメントを取得できますが、IEでは何か問題があります。
私はブレークポイントを設定し、xhr.responseXML
を印刷し、その結果がIEのネイティブなドキュメント構造ではないことがわかりました。
クローム:
#document
<CONFIG>
....
</CONFIG>
IE:私はこの問題を解決する方法カント
[object XMLDocument]{activeElement: undefined, alinkColor: "#0000ff", all: undefined, anchors: HTMLCollection {...}, applets: HTMLCollection {...}, ATTRIBUTE_NODE: 2, attributes: null, bgColor: "#ffffff", body: null, CDATA_SECTION_NODE: 4, characterSet: "utf-8", charset: "utf-8", childNodes: NodeList {...}, COMMENT_NODE: 8, compatible: MSCompatibleInfoCollection {...}, compatMode: "CSS1Compat", constructor: XMLDocument {...}, cookie: "", defaultCharset: "big5", defaultView: null, designMode: "inherit" ...}
?
おかげ
UPDATE:
var xmlData = {};
function loadXMLFile(file, cb) {
var xmlDoc = {};
if (window.ActiveObject) {
xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async = true;
xmlDoc.load(file);
xmlData = xmlDoc;
cb();
} else if (document.implementation && document.implementation.createDocument) {
var xhr= new XMLHttpRequest();
xhr.open("GET", file, true);
xhr.responseType = 'document';
xhr.overrideMimeType('text/xml');
xhr.onload = function() {
if (xhr.readyState === xhr.DONE) {
if (xhr.status === 200) {
console.log(xhr.responseXML); // reponseXML is different in Chrome and IE
xmlDoc = xhr.responseXML;
xmlData = xmlDoc;
cb();
}
}
};
xhr.send(null);
} else {
console.log('not support javascript');
}
}
function checkExist(name) {
var link = xmlData.getElementById(name).getElementsByTagName('url')[0].innerHTML; // IE appear ERROR here
// SCRIPT5007: Unable to get property 'getElementsByTagName' of undefined or null reference
var ele = document.getElementsByClassName(name);
// do somthing...
}
window.onload = function() {
loadXMLFile(file, function() {
checkExist("ID");
checkExist("NAME");
});
}
'reponseXMLはChromeとIEでは違います - コンソールに表示されているのは無関係です - そうでなければ動作しますか?つまり、コンソールにエラーが表示されますか? –
私のコードを更新しました。 Chromeではエラーなしで動作しますが、IEにはエラーがあります。コールバック関数を入力するとエラーが表示されます。コンソールに「プロパティgetElementsByTagNameを取得できません...」と表示されました –