php 仅刷新php中的一个div

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9691435/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 07:26:06  来源:igfitidea点击:

Refresh only a div in php

phphtmlajax

提问by user1241123

I have a chat box that i want to update :-) But I want only to refresh the div and not the hole page... Can someone help me??

我有一个我想更新的聊天框 :-) 但我只想刷新 div 而不是洞页面...有人可以帮助我吗??

Code:

代码:

<div align="right" id="chat">
<?php
include 'Chat.php';

?>
</div>

回答by Starx

You can't do it with a server side script like php

你不能用像php这样的服务器端脚本来做到这一点

However, Using jQuery, when you need to update the div. Simply use

但是,当您需要更新 div 时,使用 jQuery。只需使用

$("#chat").load("Chat.php");

For an example, make a request to the server when a user finishes typing on a textbox, and load the recent chat text.

例如,当用户在文本框上完成输入时向服务器发出请求,并加载最近的聊天文本。

$("#textbox").change(function() {
    $("#chat").load("Chat.php");
});

回答by yehuda

If you are not that good at Javascript or Ajax or jQuery, then you might want to create a link with a get variable like include = 1, and when it is equal to one, include another page with the information you want. But it is worth learning jQuery and the like.

如果您不太擅长 Javascript、Ajax 或 jQuery,那么您可能希望创建一个带有 get 变量(如 include = 1)的链接,当它等于 1 时,包含另一个包含您想要的信息的页面。但值得学习jQuery之类的。