【发布时间】:2017-03-14 08:38:52
【问题描述】:
我试图从另一个页面加载内容,但是当我点击“获取内容”按钮时显示错误,这里是脚本>>
$(function(){
$('#get_contect').click(function(){
$('#contect').load('page.html #pageContect');
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<html>
<header>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</header>
<button type="button" id="get_contect">get contect</button>
<body>
<div id = "contect">
</div>
</body>
<footer>
</footer>
</html>
显示的错误是:
jquery-1.10.2.js:8706 XMLHttpRequest 无法加载 file:///C:/Users/khaled%20salem/Desktop/New%20folder/page.html。叉 源请求仅支持协议方案:http、data、 chrome, chrome-extension, https, chrome-extension-resource.
【问题讨论】:
-
您通过
file:///协议运行您的代码 -
您是否在您请求的资源上启用了 CORS 标头“Access-Control-Allow-Origin”?
-
哎呀它没有启用
-
@KhaledALHajSalem 查看第一条评论