XMLHttpRequest无法加载html文件

时间:2014-03-20 06:28:06

标签: jquery

当我点击荣誉链接时,这是我得到的错误

OPTIONS file:///D:/Heena/BalajiKumar.com/accolades.html No 'Access-Control-Allow-Origin' 
header is present on the requested resource. Origin 'null' is therefore not allowed access. 

jquery-1.4.2.min.js:130

c.extend.ajax      jquery-1.4.2.min.js:130

c.fn.extend.load      jquery-1.4.2.min.js:120

(anonymous function)      index.html:68

c.event.handle      jquery-1.4.2.min.js:55

j.handle.o      jquery-1.4.2.min.js:49


XMLHttpRequest cannot load file:///D:/Heena/BalajiKumar.com/accolades.html. No 'Access-
Control-Allow-Origin' header is present on the requested resource. Origin 'null' is 
therefore not allowed access. 
任何解决方案。我在我的本地机器上运行它。

它在Web服务器上运行良好。 但我需要在本地运行

3 个答案:

答案 0 :(得分:0)

运行本地开发网络服务器。在Windows上,Wamp或XAMPP将是一个简单的选择。

您收到该错误,因为就AJAX而言,file://协议是一个不同的“起源”。只要AJAX调用和远程文件都托管在localhost上,你应该没问题。

答案 1 :(得分:0)

您正尝试通过file://协议在本地加载文件。 jQuery需要http://协议。因此,您需要一个像apache或nginx这样的Web服务器来为您的文件提供服务。

答案 2 :(得分:0)

我认为问题出在请求地址上。如果你想在本地运行它,你可以安装像WAMP这样的本地Web服务器......这样可以。