PDA

View Full Version : Help making chat appear "live"


SirChick
01-21-2010, 07:14 PM
Hey,

I have a php script which loads chat logs every X amount of seconds with a meta refresh but its very unprofessional so i want to add Ajax into the script to make it call my function and load the chat logs from my database without the appearance of the page refreshing... but i barely understand JS let alone the the complicated aspect of AJAX.

My script is in this structure:

<meta http-equiv="refresh" content="1; URL=shout.php">
<?php
function getlogs(){
//code
}

getlogs();
?>

Can some one help step me through how to implement ajax into this so it becomes a "live" appearance without it looking like its refreshing

RossMcCaughrain
01-22-2010, 05:56 PM
Try something like Prototype http://www.prototypejs.org/learn/introduction-to-ajax
It has a PeriodicalUpdater (bottom of page of that link). Sounds like exactly what your looking for

SirChick
01-22-2010, 10:34 PM
Thanks i tried it but it didn't work heres what i got:

shout.php
<script type="text/javascript"> <!--
new Ajax.PeriodicalUpdater('products', '/shout.php',
{
method: 'get',
insertion: Insertion.Top,
frequency: 1,
decay: 0
});
</script>

<?php
function read_entires($UserID,$Type){
//load logs and display them from query and while loop
}
read_entries($_SESSION['ShoutboxUsername'],'norm');
?>


But i didnt know what 'products' is meant to be ? :S

RossMcCaughrain
01-27-2010, 05:29 PM
products is the id of the area on the page where you want it to update to (it can be named anything as long as there is only one ion your page e.g.

<div id="products"></div>

/shout.php - This is where its going to go to to get the data. Whatever this script echos or prints will get written into the products div

needsomehelp
03-04-2010, 04:05 PM
Hey,

I have been trying for a few weeks to do something like this myself.

At present I am also using the refresh rate and this as i found out causes problems for both users in entering text that take longer than 30 seconds to type in, or less than that if they started midway thought the last refresh !

did you manage to get this to work and if so can you kindly share you method as i can not work out what ajax is all about.

cheers

Jason


Hey,

I have a php script which loads chat logs every X amount of seconds with a meta refresh but its very unprofessional so i want to add Ajax into the script to make it call my function and load the chat logs from my database without the appearance of the page refreshing... but i barely understand JS let alone the the complicated aspect of AJAX.

My script is in this structure:

<meta http-equiv="refresh" content="1; URL=shout.php">
<?php
function getlogs(){
//code
}

getlogs();
?>

Can some one help step me through how to implement ajax into this so it becomes a "live" appearance without it looking like its refreshing