"MLHttpRequest无法加载文件:///path/to/file.html”;错误

"MLHttpRequest cannot load file: ///path/to/file.html" error

本文关键字:to path file 错误 html 文件 MLHttpRequest quot 加载      更新时间:2023-09-26

当按下以下jquery load命令时,我正试图在div中加载一个本地html文件。

$("#div_name").load("local_html_file");

但我得到了以下错误。

MLHttpRequest cannot load file:///path/to/file.html. Received an invalid response. Origin 'null' is therefore not allowed access. 

我没有运行任何特殊的服务器。只是用Chrome运行我的html文件。我搜索了一下,知道问题是什么,但不知道如何解决。

Jquery.load()方法是一个ajax调用。

这就是为什么它在本地不起作用。。。您需要在接受HttpRequest的服务器上运行它。

之前已经讨论过:

  • Jquery:在没有Web服务器的情况下本地运行AJAX
  • AJAX代码不在本地运行