[英]i want to include a external php file into html page using javascript?
<?php
header("Content-type: text/javascript");
include("header.php");
?>
<head>
<script type="text/javascript" src="header.php"></script>
</head>
I'm trying to include a PHP (header & footer) file in an HTML file. 我正在尝试在HTML文件中包含一个PHP(页眉和页脚)文件。
The reason it needs to be HTML is this is a content provider that hosts the content and they've put a restriction on the number of characters that can be in the header (as they host it). 它必须是HTML的原因是这是一个托管内容的内容提供程序,并且他们限制了标头中(可以承载标头中)字符的数量。 Any ideas?
有任何想法吗?
You can not include php in a html page, as php generates html but html can not generate php. 您不能在html页面中包含php,因为php会生成html,但是html无法生成php。 So you can try ajax method to include php instead on page load try calling a javascript function which will call the php file.
因此,您可以尝试在页面加载时尝试使用ajax方法来包含php,然后尝试调用javascript函数来调用php文件。
window.location.assign("header.php"); window.location.assign(“ header.php”); by this method you can add php file but only in php page..not with html.
通过这种方法,您可以添加php文件,但只能在php页面中添加。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.