how to read xml data in IE browser using jquery Ajax function

前端 未结 4 1581
悲哀的现实
悲哀的现实 2021-01-24 21:06

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

4条回答
  •  梦毁少年i
    2021-01-24 21:40

    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;
    }
    

提交回复
热议问题