.load 使用 file.php 重新加载 div
用 php 文件重新加载 div 的方法是什么?我在 HTML 页面中定义了一个这样的 div。
HTML
<div id="tnav"
<?php require("loadtree.php"); ?>
</div>
我有一个 PHP 文件,它执行数据库操作,然后调用 div 上的 load 方法来重新加载。
<?php
.
.
.
echo "<script type='text/javascript'> $('#tnav').load('loadtree.php'); </script>";
?>
该脚本在源中回显,但这不会导致页面重新加载。可能是什么问题?
What's the way to reload a div with a php file. I have a div defined like this in the HTML page.
HTML
<div id="tnav"
<?php require("loadtree.php"); ?>
</div>
I have a PHP file that peforms database actions then calls the load method on the div to reload.
<?php
.
.
.
echo "<script type='text/javascript'> $('#tnav').load('loadtree.php'); </script>";
?>
The script echoes in the source, but this does not cause the page to reload. What could be the problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我正在做类似的事情,我需要在一个页面上有多个 div,并将 GET 变量传递给包含的 div,然后当触发触发器时,我需要使用 jQuery 分别重新加载每个单独的 div(在本例中,在图片上传)。如果这对任何人有任何帮助,我就是这样做的:
在主脚本中,我声明了多个 div,每个 div 都有一个由构造循环生成的唯一 id:
接下来,我使用另一个循环来初始化 JS onload 事件(现在这个我觉得可以比使用 10 个单个 onload 事件更有效..):
最后,我希望每个 div 在相关触发器被触发时独立于其他 div 重新加载。在本例中,我的触发器是一个正在关闭的 colorbox,因此我为我需要的每个触发器分配了一个 colorbox 实例,并将 onClosed 触发器绑定到每个 div 的函数。由于每个 div 都分配了一个唯一的名称,因此我可以按如下方式执行此操作:
无论是否包含在颜色盒触发线中,该功能都是相同的。
我意识到这是一篇巨大的帖子,超出了您实际要求的内容,但我花了几周的时间寻找这样的解决方案,但无法找到解决方案,所以希望这会对某人有所帮助!
I was doing something similar and I needed to have multiple divs on one page with GET variables passed to the included divs, then I needed to reload each individual div separately with jQuery when a trigger was fired (closing a colorbox in this instance, after an image upload). If it is of any help to anyone, this is how I did it:
In the main script I declared multiple divs, each with a unique id generated by the construction loop:
Next I used another loop to initialise the JS onload events (now this bit I feel could be done more efficiently than using 10 single onload events..):
Finally I wanted each div to reload independently of the others when the relevant trigger was fired. In this case my trigger was a colorbox being closed, so I assigned an instance of colorbox for each of the triggers I needed and tied the onClosed trigger to a function for each div. As each div had a unique name assigned to it I could do this as follows:
The function is the same whether encased in the colorbox firing line or not.
I realise this is a huge post and more than you've actually asked for, but I spent weeks looking for a solution like this and couldn't fine one, so hopefully this will help someone!
PHP 在页面加载之前在服务器端执行。页面加载后,PHP 无法访问该页面。您应该考虑使用 JavaScript(或 jQuery?)来重新加载页面,具体取决于您具体想要做什么。
在脚本输出中添加倒计时器以使用 JavaScript 重新加载页面。
PHP is executed server-side, before the page loads. After the page loads, PHP has no access to the page. You should look into using either JavaScript (or jQuery?) to reload the page, depending on what you are specifically trying to do.
Add a countdown timer in the script output to reload the page using JavaScript.
如果您添加应在页面加载时执行的内容,请
按照您的情况这样做,
If you add your contents which should be executed on page load, do it this way
so in your case,
试试这个
或者,如果您想让代码更具可读性,请在 php 标记之外编写脚本,以便突出显示语法。
Try this
Or, if you want to make your code a little more readable, write the script outside of the php tags so it gets syntax highlighted.
必须将 div 更改为 iframe,然后像这样重新加载 iframe。
Had to change the div to an iframe then reloaded the iframe like this.