The issue:
Internet Explorer won’t parse XML quite as easily as every other browser on the internet (I assume). You have to change what you pass it as through jQuery. In IE it has to be passed as text, while the rest can handle it as XML. You also have to pass it through a separate function that brings in ActiveX before you can navigate your way through the XML and use it in your application.
The solution:
Set the type to “text” for IE and “xml” for the rest.
<code>$.ajax({
type: 'GET',
url: 'sample.xml', // your xml file
dataType: ($.browser.msie) ? "text" : "xml", // text for IE, xml for the rest
success: function(xml) {
var newXML = parseXml(xml);
// and then process normally
}, // end success
error: function(a, b, c) {
alert('error'); // this is where the errors happen, 'b' and 'c' are typically the only ones with values
} // end error
}); // end .ajax
function parseXml(xml) {
if (jQuery.browser.msie) {
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.loadXML(xml);
xml = xmlDoc;
}
return xml;
}</code><a href="http://codepen.io/jeremyHixon/pen/HjFKk">Check out this Pen!</a>
Reference the function in your .ajax()
success: function(xml) {
var newXML = parseXml(xml);
$(newXML).find().... And…voila!
[...] You can get the function and instructions for IE here: jQuery, AJAX and Internet Explorer [...]
This issue was driving me crazy for hours! Thanks a lot for the solution. I was examing my code bit by bit, I even came to become suspicious about my RSS generator, until I found your blog and voilá! Problem solved. I guess jQuery isn’t so cross-browser after all.
Thanks again.
You’re most welcome
Thank you for this!!!
i have used the same and it doesnt work for me i couldnt guess why can any one help
Can you post your code?
Many thanks…!!!
Muchas gracias desde Chile… me salvaste una tarde de esfuerzo!
[...] I don’t know how IE handles the “HTML” dataType but I know it struggles with XML. If this causes problems for you in IE, you I might suggest reading this topic: jQuery, AJAX and Internet Explorer [...]
thanks, i had the same problem, this was very helpful
That’s a sensible answer to a challenging qeusiton
This was kicking my ass today. Nice solution, thanks!
Thankyou so much!!
Hello , thanks for the code but i still cant read from IE .. can you help me please
here is the Code :
function parseXml(xml) {
if (jQuery.browser.msie) {
var xmlDoc = new ActiveXObject(“Microsoft.XMLDOM”);
xmlDoc.loadXML(xml);
xml = xmlDoc;
}
return xml;
}
$.ajax({
type: “GET”,
url: myXML path, //xml file
dataType: ($.browser.msie) ? “text” : “xml” ,
success: function(xml) {
var newXML = parseXml(xml);
var count = 0; //counter
$(newXML).find(‘item’).each(function() {
var title = $(this).find(‘title’).text();
var url = $(this).find(‘guid’).text(); //url
var imageURL = $(this).find(‘enclosure’).attr(“url”); //location of the image
var desc = $(this).find(‘description’).text(); //alternate text of the image
images[parseInt(count)] = new Array(imageURL);
titles[parseInt(count)] = new Array(title);
urls[parseInt(count)] = new Array(url);
descs[parseInt(count)] = new Array(desc);
count++;
});
@Yamen Al-Haj:
First of all, is it working in Firefox and not IE or not working in either?
Second, a question. did you check the filename that goes in the “url” of the ajax call?
Third, I can’t find where the closing bracket is for your “success” function. Looking at your code I’d think it would be just before the closing of your .ajax function. Something like this, would be the last two lines of your code:
}
});
Nice workaround. Why can’t IE be like the rest of them??
Thanks a lot. I googled for 6 hrs and finally got the solution. Nice Work Buddy.
Thanks buddy…solution is working fine in IE….great job.
Yeah, baby! This example helped put that little brat IE in his place. From now on, it will behave like its peers.
Thanks for the tip, you saved the day!
I m getting exception in this line
xmlDoc.loadXML(xml);
“Type Mismatch”
Check the “dataType” and make sure it matches the type of data you’re requesting. A quick Google looks like most of the time that happens when you try to pull in a JSON response through the XML parser or if the XML document doesn’t have a root element.