Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
680 views
in Technique[技术] by (71.8m points)

xml - Local html file AJAX Call and jQuery Woes

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...