douyinzha5820
douyinzha5820
2014-10-13 07:08
浏览 60

JavaScript:在div中加载包含PHP函数的文件

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.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

2条回答 默认 最新

  • duanmao1919
    duanmao1919 2014-10-13 07:16
    已采纳

    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

    点赞 评论
  • doujianqin5172
    doujianqin5172 2014-10-13 07:26

    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()

    点赞 评论

相关推荐