I need to read xml data using jquery in AJAX function, which is working fine in firefox... however i am stuck with IE browser... I am not able to read xml. program is required t
You no need to repeat the xml file name and do the same operations again in parseXML unnecessarily.
The trick here is to disable the caching. But still IE sometimes doesn't disable caching. Hence add the timestamp as a query string along with your xml file name in the url which solves the problem. I tested it and worked 100% on IE and other browsers.
$.ajax({
type: 'GET',
url: "XML_file.xml?timestamp=" + new Date().getTime(), // add the timestamp to the url to avoid caching in IE
dataType: ($.browser.msie) ? "text" : "xml",
cache: "false",
success: function (xml) {
var processedXML = parseXml(xml);
$(processedXML).find('my record').each(function () { //code }
}
});
function parseXml(xml) {
if (jQuery.browser.msie) { // Only for IE
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.async="false";
xmlDoc.loadXML(xml);
xml = xmlDoc;
}
return xml;
}