2

I am using jQuery.ajax to parse some xml from a file. Everything works fine in IE (6,7,8), Firefox, Opera and Safari, but fails with Google Chrome. Here is the code:

/* ... */
this.loadXml = function()
{
 $.ajax(
 {
  type: "GET",
  url: "some_file.xml",
  dataType: ($.browser.msie) ? "text" : "xml",
  success: function(xml)
  {
   if($.browser.msie)
   {
    var xmlDoc = new ActiveXObject("Microsoft.XMLDOM");
    xmlDoc.loadXML(xml);
    xml = xmlDoc;
   }

  /* parsing starts here */
  /* for example: in the document I have a div tag with id "some text" and the xml file contains: <root><tag>test</tag></root>*/

  $("#some_id").text($(xml).find("root > tag").text());

  /* parsing ends here */

  }
 });
}
Vasilen Donchev
  • 975
  • 4
  • 14
  • 26

2 Answers2

2

Chrome is not going to let you access a local file like that. It's a (somewhat contentious) security thing. You can start chrome from the command line with a flag to force it to allow access however:

google-chrome --allow-file-access-from-files

(My thanks for this again to @Nick Craver, man of infinite knowledge.)

edit — here's the question I asked: Accessing relative URL's via "ajax" from "file://" content

Community
  • 1
  • 1
Pointy
  • 405,095
  • 59
  • 585
  • 614
-1

just replace the short url with the full url...

from

url: "some_file.xml",

to

url: "http://www.domain.com/some_file.xml",

Pipebugs
  • 99
  • 1
  • 3