March 13, 2012
Refresh only a div in php
Question 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??
Code:
<div align="right" id="chat">
<?php
include 'Chat.php';
?>
</div>
Answer by Starx
You can’t do it with a server side script like php
However, Using jQuery, when you need to update the div. Simply use
$("#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");
});