我有两个文件:HTML和JavaScript。名称是culminating.html和javascript.js。我在.js文件中有jQuery代码,它应该将文本文件的内容发送到div
bottom_pane_options。
这是jQuery代码:
$(document).ready(function() {
$("#readFile").click(function() {
$.get('./test.txt', function(data) {
$("#bottom_pane_options").html(data);
}, 'text');
});
});
和html:
<!DOCTYPE html>
<html>
<head>
<title>Culminating</title>
<link href="style.css" rel="stylesheet" type="text/css">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min.js"></script>
<script type="text/javascript" src="./javascript.js"></script>
<script src="http://maps.googleapis.com/maps/api/js?key=AIzaSyCJnj2nWoM86eU8Bq2G4lSNz3udIkZT4YY&sensor=false"></script>
</head>
<body>
<div class="content">
<div id="googleMap"></div>
<div id="right_pane_results">hi</div>
<div id="bottom_pane_options">
<button onclick="get_parameters()">Try It</button>
<button id="readFile">Read File</button>
</div>
</div>
</body>
使用此代码,我收到错误:
No 'Access-Control-Allow-Origin' header is present on the requested resource.
和
XMLHttpRequest cannot load file:///G:/test.txt. No 'Access-Control-Allow-Origin' header is present on the requested resource.
我知道我需要添加Access-Control-Allow-Origin: *
,但我不知道在哪里。