如何使用jQuery添加公共页眉页脚

时间:2018-02-05 05:05:53

标签: javascript jquery

我正在尝试使用jQuery创建通用页眉。我正在使用此功能,但它没有从header.html加载内容,它在控制台中显示错误(见图)

Error message

dict

这是我的完整html页面标记

<script type="text/javascript">
    $(function(){
    $("[data-load]").each(function(){
        $(this).load($(this).data("load"), function(){
        });
    });
})
</script>

2 个答案:

答案 0 :(得分:2)

您需要从服务器提供文件,可能是localhost,而不是简单地在浏览器中打开html文件。

错误消息是试图说明{I}}协议不允许您尝试执行此操作。

最好设置本地服务器。您可以使用http-serverlive-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