简体   繁体   English

如何使用jquery ajax在离线站点中设置url

[英]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. 纯HTML,我需要加载和读取XML文件并使用结果更新页面。

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. 如果文件位于同一位置,则该任务已完成并且可以读取xml文件,问题是如果xml文件位于ajax无法使用的单独文件夹中,则该问题会出现。 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. 情况-1对我来说是可行的解决方案,但是我需要将xml文件放在单独的位置。

Then the case - 2 is the way to get to the file which is getting failed. 然后情况-2是获取失败文件的方法。

any idea, 任何想法,

Actually no domain, no servers, its is pure HTML, 实际上没有域,没有服务器,它是纯HTML,

All files are in ex: 所有文件都在ex中:

D:/myfiles/someFolder/index.html D:/myfiles/someFolder/index.html

If i put the file in 如果我把文件放进去

D:/myfiles/someFolder/xml/myxml.xml and set the url as D:/myfiles/someFolder/xml/myxml.xml并将URL设置为

url: "xml/myxml.xml" 网址:“ xml / myxml.xml”

this config is working too, 这个配置也可以

But i'm trying to place the xml file in 但我试图将xml文件放入

D:/myfiles/xml/myxml.xml and need to read the file using ajax setting the url as D:/myfiles/xml/myxml.xml,并且需要使用ajax将URL设置为读取文件

url: "../xml/myxml.xml" 网址:“ ../ xml / myxml.xml”

尝试使用绝对网址:

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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