dt3358 2012-08-10 13:21
浏览 85
已采纳

如何将php文件调用为div?

I'm trying to reload only specific div

$("#captcha").html('<?php echo 'abc';?>'); // just as test - works well

Because div content is much larger, I tried:

$("#captcha").html('<?php include 'myFile.php';?>'); // doesn't work

How can I call the code from a .php file into a div ?

  • 写回答

5条回答 默认 最新

  • duanfu3634 2012-08-10 13:23
    关注

    use $('div').load('phpfile.php')

    $.load is used to load data from the server via an html file or a server-side script like php. Just to have an overview of what you can do with $.load you can also load page fragments by including a selector after the page you want to retrieve. This way only the contents of the selected element will be loaded into your container. You can also pass in data and execute functions after the request has complete(callbacks).

    $.html is different because its only used to get or set the contents of an existing element. You can however use it with ajax methods like $.post, $.get, $.ajax to update the contents of an existing element.

    Read up jQuery's documentation on the $.load and $.html methods if you want to have an in-depth understanding on how these method works.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(4条)

报告相同问题?

悬赏问题

  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 关于大棚监测的pcb板设计
  • ¥15 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入