简体   繁体   中英

How to set the url in off-line site using jquery ajax

well my task is running a static site, No servers at all. pure HTML, and i need to load and read an XML file and update the page with the result.

The task is done and can read the xml file if the file is in the same location, the problem is if the xml file is in a separate folder the ajax flails. seems like the url fails.

$.ajax({
  type: "GET",

  // working url setting - case - 1
  // url: "somexmlfile.xml",

  // not working - case - 2
  url: "../somepath/somexmlfile.xml",

  dataType: "xml",
  success: function(xml){
    // do something with the returned data
  },
  error: function() {
    // display the error
  }
});

Case - 1 is the working solution for me, but i need to place the xml file in a separate place.

Then the case - 2 is the way to get to the file which is getting failed.

any idea,

Actually no domain, no servers, its is pure HTML,

All files are in ex:

D:/myfiles/someFolder/index.html

If i put the file in

D:/myfiles/someFolder/xml/myxml.xml and set the url as

url: "xml/myxml.xml"

this config is working too,

But i'm trying to place the xml file in

D:/myfiles/xml/myxml.xml and need to read the file using ajax setting the url as

url: "../xml/myxml.xml"

尝试使用绝对网址:

www.yourdomain.ext/siteDolder/xmlFolder/xmlfile.xml

最后,解决方案是在Firefox设置上关闭浏览器安全性(在about:config上strict_origin_policy设置为false),并且可以正常工作。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM