简体   繁体   中英

JavaScript: load file that contain include PHP fucntion in div

I have this situation.

file.html

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

myjsfile.js

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

myphpfile.html

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

The content of myphpfile.php is not viewed. How can I show the content of myphpfile.php in selected div?

Thanks.

You can use php also in load funtion.

$(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..

Use this script file for library jquery-1.9.1.js

We could not able to include PHP file with in HTML file. You have to call php file instead of HTML file. In PHP, there are many function to include Myfile.php file. please find the include function as below:

include()

require()

include_once()

require_once()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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