5

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>
user1241123
  • 55
  • 1
  • 1
  • 4

3 Answers3

6

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");
});
Starx
  • 77,474
  • 47
  • 185
  • 261
3

checkout this one. Its easy to implement and pretty useful.

http://www.9lessons.info/2009/07/auto-load-refresh-every-10-seconds-with.html

also see this

Auto-refreshing div with jQuery - setTimeout or another method?

Good luck..

Community
  • 1
  • 1
Milap
  • 6,915
  • 8
  • 26
  • 46
  • What is wrong with this code
    – user1241123 Mar 13 '12 at 20:50
0

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.

yehuda
  • 1,254
  • 2
  • 11
  • 21