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

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");
});

Author: Nabin Nepal (Starx)

Hello, I am Nabin Nepal and you can call me Starx. This is my blog where write about my life and my involvements. I am a Software Developer, A Cyclist and a Realist. I hope you will find my blog interesting. Follow me on Google+

...

Please fill the form - I will response as fast as I can!