在有人将这个问题标记为重复之前,我已经对此进行了大量的调查,但我仍然没有找到解决我的问题的方法。
所以,我有这些header.html和footer.html文件,并且我想将它们的内容加载到一个新的html页面中(尽量不重复代码)。我知道我可以用PHP来很容易地实现这个目标,但我正在尝试使用JQuery(刚开始挖掘它)。这是我到目前为止的代码:
我遇到了以下错误:
jquery.min.js:5 XMLHttpRequest无法加载 file:///C:/Users/...../footer.html。跨域请求仅支持协议方案:http、data、chrome、chrome-extension、https、chrome-extension-resource。send @ jquery.min.js:5ajax @ jquery.min.js:5b.fn.load @ jquery.min.js:5(anonymous function) @ index.html:10c @ jquery.min.js:3fireWith @ jquery.min.js:3ready @ jquery.min.js:3H @ jquery.min.js:3
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="./style.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script>
$(function(){
$('#filename').load("footer.html");
});
</script>
</head>
<body>
<div id="filename"></div>
</body>
</html>
我遇到了以下错误:
jquery.min.js:5 XMLHttpRequest无法加载 file:///C:/Users/...../footer.html。跨域请求仅支持协议方案:http、data、chrome、chrome-extension、https、chrome-extension-resource。send @ jquery.min.js:5ajax @ jquery.min.js:5b.fn.load @ jquery.min.js:5(anonymous function) @ index.html:10c @ jquery.min.js:3fireWith @ jquery.min.js:3ready @ jquery.min.js:3H @ jquery.min.js:3
footer.html
请求的响应头吗? - Brad