IEにおけるresponseXMLの問題点
今まで謎だったことが解明
以下の問題を修正するうえで、XMLHttpRequestオブジェクトのresponseXMLを解決方法として使用しました。
チケット #26764 ActiveXが無効だと作動せずにエラー
http://sourceforge.jp/ticket/browse.php?group_id=3313&tid=26764#preview
ところが、なぜか、responseXMLのdocumentElementがnullとなってしまい、新たなバグが発生しています。
そこで、昨日から今日にかけて調べていたのですが、ようやく、謎が解けました。
IE8はcontent-typeに厳しい
IE7とIE8で実装されているXMLHttpRequesetは、responseXMLに対して、「content-typeがtext/xmlかapplication/xmlでないとresponseXMLを使って取得することができない」(注1)ということらしいのです。
SIEでは、image/svg+xmlなので
当然、responseXMLが取得できなくなります。ただし、responseTextは取得できますので、以下のような解決方法があります(注2)。この方法を採用したいと思っています。
var result = xmlhttp.responseXML;
if (!result.documentElement && xmlhttp.responseStream) {
result.load(xmlhttp.responseStream);
}
注1
(超)実験室「BloggerのFeedのcontent-type」より引用
http://jikkenshitsu.blogspot.com/2006/11/bloggerfeedcontent-type.html
注2
KC-Luck氏のコメントより引用
http://www.codingforums.com/archive/index.php/t-79228.html