呈现以下HTML文档:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>Loading data</title>
<script type="text/javascript" src="d3.js?2.7.4"></script>
<script type="text/javascript" src="d3.csv.js?2.7.4"></script>
<style type="text/css">
@import url("style.css?1.10.0");
</style>
</head>
<body>
<div align="center">
<h1>Loading data</h1>
</div>
<div id='chart' align="center">
<svg class="svg_area" width="800" height="400">
</svg>
</div>
</body>
<script type="text/javascript">
var data=[];
d3.csv("coordinates.csv",
function(rows){
var svg=d3.select("svg");
svg.selectAll("circle").data(rows).enter()
.append("circle")
.attr("cx",function(d){return d.x;})
.attr("cy",function(d){return d.y;})
.attr("r","10")
.attr("fill","green");
}
);
</script>
它在JavaScript控制台中出现以下错误:
XMLHttpRequest cannot load file:///C:/Users/Admin/Desktop/Engineer/Ongoing/…0Visualization/Slides/1)%20Introduction%20to%20d3/coordinates.csv. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.d3.xhr @ d3.js:434
Uncaught NetworkError: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///C:/Users/Admin/Desktop/Engineer/Ongoing/…0Visualization/Slides/1)%20Introduction%20to%20d3/coordinates.csv'. @ d3.js:434
我的问题是:为什么这是跨域请求?
只要我理解,javascript的源域是C://,而.csv位于同一个文件系统上。那么为什么浏览器会将此识别为&#34;跨域&#34; ?
哪种解决办法最简洁?