【问题标题】:Access to XMLHttpRequest from origin 'null' has been blocked by CORS Policy?CORS 策略已阻止从源“null”访问 XMLHttpRequest?
【发布时间】:2020-08-16 04:21:09
【问题描述】:

我是 javascript 和 Web 开发的新手,但我正在尝试从我的桌面学习使用 d3 一个 csv 文件。我的代码如下:

<!DOCTYPE html>
<html lang = "en">
   <head>
      <script src = "https://d3js.org/d3.v4.min.js"></script>
   </head>

   <body>
      <script>
        d3.csv("csv_file.csv", function(data){
            console.log(data);
        });
      </script>
   </body>
</html>

但是,我收到错误消息:

Access to XMLHttpRequest at 'file:///Users/Desktop/College_Finder/csv_file.csv' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
index.html:10 null

我不知道这意味着什么或如何解决它

【问题讨论】:

  • 我不确定,但有人问过类似的问题here。

标签: javascript html d3.js xmlhttprequest


【解决方案1】:

您必须在本地服务器上运行您的代码。

例如:

webstorm,phpstorm 或任何 IDE 都可以使本地服务器运行

【讨论】:

    猜你喜欢
    • 2019-04-28
    • 2021-03-08
    • 2021-01-14
    • 2019-12-15
    • 2017-06-17
    • 2019-07-09
    • 2019-12-18
    • 2023-03-09
    • 2019-10-30
    相关资源
    最近更新 更多