我知道如何使用
指向外部javascript文件 <script src="data.js"></script>
您将如何指向外部文本(.txt)或csv文件?在下面的代码中,我无法指向test.txt。
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>crossfilter + maps</title>
<link href="style.css" rel="stylesheet" type="text/css" media="all">
<script src="chart.js"></script>
<script src="setup2.js"></script>
<script src="data.js"></script>
<script src="test.txt"></script>
<script>
document.addEventListener('DOMContentLoaded', init, false);
</script>
答案 0 :(得分:1)
HTML
<div id='fileContainer'></div>
JS
document.addEventListener('DOMContentLoaded', function () {
var fileContainer = document.getElementById('fileContainer');
var xhr = new XMLHttpRequest();
xhr.onload = function () {
fileContainer.innerHTML = this.response;
};
xhr.open('GET', 'myFile.csv', true);
xhr.send();
}, false);