开发者

Is it possible to parse xml in jQuery (in IE) that didn't come from an ajax call?

It looks like it works in Safari and Firefox but not in IE. I have an arbitrary string of XML which comes from a Flash response (it's complicated).

Here's a JSFiddle which tries to find a simple tag in the XML: http://jsfiddle.net/MJSa8/5/

I've read elsewhere that when it comes to the Ajax responder, you have to be sure to set the content type to xml to make it work in IE, but this is just a string of XML. Is there some way to force IE to treat it as XML?

Edit: Also putting the code example here for reference:

var xml ='<postresponse><location>http://something.s3.amazonaws.com/15o96sf3h1div1auj121e1oc3j1u.png</location><bucket>something</bucket><key>15o96sf3h1div1auj121e1oc3j1u.png</key>&l开发者_运维技巧t;etag>"85d3db1aaeb47aecaace540c7ce7a609"</etag></postresponse>';
var len = $(xml).find('location').length;
$('#output').text(len);


try this:

var xml ='<postresponse><location>http://something.s3.amazonaws.com/15o96sf3h1div1auj121e1oc3j1u.png</location><bucket>something</bucket><key>15o96sf3h1div1auj121e1oc3j1u.png</key><etag>"85d3db1aaeb47aecaace540c7ce7a609"</etag></postresponse>';

if (window.DOMParser)
{
    parser=new DOMParser();
    xmlDoc=parser.parseFromString(xml,"text/xml");
}
else // Internet Explorer
{
    xmlDoc=new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.async="false";
    xmlDoc.loadXML(xml); 
} 
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜