Local html file AJAX Call and jQuery Woes

心不动则不痛 提交于 2019-11-27 04:21:29

问题


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


回答1:


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.




回答2:


Just a thought: I remember some GET requests failures with IE. Have you tried POSTing it?



来源:https://stackoverflow.com/questions/436670/local-html-file-ajax-call-and-jquery-woes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!