我正在尝试使用jQuery创建通用页眉。我正在使用此功能,但它没有从header.html加载内容,它在控制台中显示错误(见图)
dict
这是我的完整html页面标记
<script type="text/javascript">
$(function(){
$("[data-load]").each(function(){
$(this).load($(this).data("load"), function(){
});
});
})
</script>
答案 0 :(得分:2)
您需要从服务器提供文件,可能是localhost
,而不是简单地在浏览器中打开html文件。
错误消息是试图说明{I}}协议不允许您尝试执行此操作。
最好设置本地服务器。您可以使用http-server或live-server轻松完成此操作。
如果您没有安装node,请先安装它。
答案 1 :(得分:0)
你应该使用localserver,你可以使用node.js命令提示符
first access your directory and execute the following command :
http-server . -p 8000
then you can access using the url : http://127.0.0.1:8000