I'm working on a offline version of a website using jQuery and some xml files. I'm running in to a problem in jQuery when I do a $.ajax call on a xml file jQuery throws a error.
When I look at the error I can tell its loading the XML file because its in the error's responceText property. It seams to work just fine in Firefox.
This is how my call looks
$.ajax({
type: "GET",
url: "Modules/" + ModuleID + "/ModuleContent.xml",
dataType: "xml",
success: function(x) { xml = x; ProcessXML(); },
error: function(x) { alert(x.responceText); }
});
When I run this on a web server it works just fine. Its only when I run it from the file its self when I have this problem.
Any ideas on how I can make this work in IE?
Edit: I found the answer to my problem. Here
From the link that the OP posted with the answer:
When loading XML files locally, e.g. a CD-ROM etc., the data received by Internet Explorer is plain-text, not text/xml. In this case, use the dataType parameter to load the xml file as text, and parse the returned data within the succes function
$.ajax({
url: "data.xml",
dataType: ($.browser.msie) ? "text" : "xml",
success: function(data){
var xml;
if (typeof data == "string") {
xml = new ActiveXObject("Microsoft.XMLDOM");
xml.async = false;
xml.loadXML(data);
} else {
xml = data;
}
// Returned data available in object "xml"
}
});
This worked for me as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With