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
finally I have found the solution, the trick is use separate code XML for IE browsers that are version of less than 10 .
so every time Ajax is call a method parseXml is called with input parameter XML Dom or text, depending on browser .... and if current browser is IE, it upload XML doc, process it according to Microsoft standards and return XML and rest of processes in Ajax carries on as expected!!
note : browser.msie is not supported in jQuery 1.9 but you can add jquery-migrate-1.2.1.min.js in order to make it compatible or use userAgent and find which is current browser
$.ajax({
type: 'GET',
url: 'XML_file.xml',
dataType: ($.browser.msie) ? "text" : "xml",
success: function (xml) {
var processedXML = parseXml(xml);
$(processedXML).find('my record').each(function () { //code }
});
function parseXml(xml) {
if ($.browser.msie) {
if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
xmlhttp = new XMLHttpRequest();
}
else {// code for IE6, IE5
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.open("GET", "XML_file.xml", false);
xmlhttp.send();
xmlDoc = xmlhttp.responseXML;
xml = xmlDoc;
}
return xml;
}
function parseXML(xml) {
if (jQuery.browser.msie) {
alert("dd3");
var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
xmlDoc.loadXML(xml);
xml = xmlDoc;
}
alert("dd4");
return xml;
}
function searchThis() {
alert("dd1");
$.ajax({
type: "GET",
url: XMLSource,
dataType: ($.browser.msie) ? "text" : "xml",
success: function (xml) {
alert("dd2");
var newXML = parseXML(xml);
loadPublication(newXML)
}
});
}
enjoy with this working for IE.
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;
}
i manage problem with chrome by adding chrome.exe --allow-file-access-from-files to its property target location but not getting for IE. please any one can then post your answer.