2014-09-12 99 views
0

我试图使用href连接到同一目录中的HTML文件,但它给我一个错误加载页面。无法使用jQuery按钮链接连接外部HTML文件

它提供了以下错误:

XMLHttpRequest cannot load file:///C:/Users/Nadeesha/Desktop/Collect/FounderR.html. Received an invalid response. Origin 'null' is therefore not allowed access. 

我能做些什么来解决这个问题?

<a data-theme="d" data-corners="false" data-role="button" href="FounderR.html"> 
     <img src="images/icons/round/64x64/entr.gif" alt="entr" style="display: block; margin: 0 auto"> 
     Founder 
</a> 
+2

这是什么都与jQuery做?这是一个基本的HTML锚点。 – isherwood 2014-09-12 19:25:14

+0

上面的代码将完美工作。上面给出的代码中没有Jquery的作用。您的Founder.html是否正确加载为独立文件? – Akhil 2014-09-12 19:28:59

+0

我正在用jquery,javaScript和html构建一个SPA。最近我用id从一个段跳到另一个段,在这里我需要访问一个外部html文件,但是应用程序不允许这样做 – 2014-09-12 19:29:53

回答

1

如果您正在使用chrome,并且我假设您是这样,那么您在使用localhost时将面临CORS问题。

生病建议您阅读本:

https://developers.google.com/storage/docs/cross-origin?hl=es

+0

Nadeesha的文件与请求它们的资源位于相同的目录中。这不会违反同源政策。 – Jerreck 2014-09-12 20:38:59

+0

是的。看到他正在使用的网址。请阅读我留在评论中的文件。 – 2014-09-12 20:44:32

+0

啊,我阅读[this]后有意义(http://stackoverflow.com/questions/4208530/xmlhttprequest-origin-null-is-not-allowed-access-control-allow-origin-for-file)。我的错。 – Jerreck 2014-09-12 20:55:07