如何将php文件调用为div? [英] How to call php file into a div?

查看:136
本文介绍了如何将php文件调用为div?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试重新加载特定的div

I'm trying to reload only specific div

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

因为div内容要大得多,我试过:

Because div content is much larger, I tried:

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

如何将.php文件中的代码调用为div?

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

推荐答案

使用 $('div')。load('phpfile.php')

$ .load 用于通过html文件或服务器从服务器加载数据像php一样的脚本。
只是为了概述你可以用 $。load 做什么,你也可以通过在你想要检索的页面之后包含一个选择器来加载页面片段。这样只会将所选元素的内容加载到容器中。您还可以在请求完成后传递数据并执行函数(回调)。

$.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 是不同,因为它仅用于获取或设置现有元素的内容。
然而,你可以使用ajax方法,如 $ .post $。get $。ajax 更新现有元素的内容

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

阅读jQuery关于 $。加载 $。html 方法
如果你想深入了解这些方法是如何工作的。

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.

这篇关于如何将php文件调用为div?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆