热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

PHP:@include_once用于动态加载的内容?-PHP:@include_oncefordynamicallyloadedcontent?

Ihavethisheader.phpwhichIincludedinallthepagesIneedit.Iused@include_once(header.php

I have this header.php which I included in all the pages I need it. I used @include_once('header.php'); in order to be able to load the page via AJAX into the "container" div of another page without having to worry about it being showed twice. But since both the main page and the loaded page have the header included, the header is showing twice. I thought include_once was supposed to not let that happen. What should I do?

我有这个header.php,我把它包含在我需要它的所有页面中。我使用了@include_once('header.php');为了能够通过AJAX将页面加载到另一个页面的“容器”div中,而不必担心它被显示两次。但由于主页面和加载页面都包含标题,标题显示两次。我认为include_once应该不会让这种情况发生。我该怎么办?

1 个解决方案

#1


0  

Jon's recommendation is the "right way" -- re-architect your system so the header is included only when it's needed.

Jon的建议是“正确的方式” - 重新设计您的系统,以便仅在需要时才包含标题。

However, as an (computationally expensive) workaround, in your code that includes the header via AJAX, you can check for the existence of an element that only exists in header.php:

但是,作为(计算上昂贵的)解决方法,在包含通过AJAX标头的代码中,您可以检查是否存在仅存在于header.php中的元素:

//We know that the string "

推荐阅读
author-avatar
丨为你
这个家伙很懒,什么也没留下!
Tags | 热门标签
RankList | 热门文章
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有