简体   繁体   English

JavaScript:在div中包含包含PHP功能的文件

[英]JavaScript: load file that contain include PHP fucntion in div

I have this situation. 我有这种情况。

file.html file.html

.......
<div id="mydiv">
</div>
.......

myjsfile.js myjsfile.js

............
$("#mydiv").load("myphpfile.html");
............

myphpfile.html myphpfile.html

............
<?php
    include("myfile.php");
?>
............

The content of myphpfile.php is not viewed. 无法查看myphpfile.php的内容。 How can I show the content of myphpfile.php in selected div? 如何在选定的div中显示myphpfile.php的内容?

Thanks. 谢谢。

You can use php also in load funtion. 您也可以在加载函数中使用php。

$(document).ready(function(e) {
         $("#mydiv").load("myfile.php");
});

Above code will load after page loaded 上面的代码将在页面加载后加载

include("myfile.php");

include function will run before loading html and javascript codes.. include函数将在加载html和javascript代码之前运行。

Use this script file for library jquery-1.9.1.js 将此脚本文件用于库jquery-1.9.1.js

We could not able to include PHP file with in HTML file. 我们无法在HTML文件中包含PHP文件。 You have to call php file instead of HTML file. 您必须调用php文件而不是HTML文件。 In PHP, there are many function to include Myfile.php file. 在PHP中,有很多函数可以包含Myfile.php文件。 please find the include function as below: 请找到以下包含函数:

include() 包括()

require() 要求()

include_once() include_once()

require_once() require_once()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM