dcsimg
Ajax Chat
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   slaven_miric
Posted On:   Wednesday, June 21, 2006 09:46 AM

Qisland CHAT Hello! I'm started create simple Chat with Ajax! I'm finish basic chat, but they have a problem. When i activate my function timer from onload="getDataFromServer()"> then always a got old XML from server. Under this i think i got XML with data witch was there when i'm inicialize me chat page, although in meantime i set new data to database. When i send new data to server, server insert this data to database and return me again "old" XML. If i turn off timer function, then everything is ok, but always i must click send button to get data from server, and this is not dinamic. And i'm now los   More>>
Qisland CHAT

Hello!



I'm started create simple Chat with Ajax!



I'm finish basic chat, but they have a problem.



When i activate my function timer from
onload="getDataFromServer()"> then always a got old XML from
server. Under this i think i got XML with data witch was there when i'm
inicialize me chat page, although in meantime i set new data to database.



When i send new data to server, server insert this data to
database and return me again "old" XML.




If i turn off timer function, then everything is ok, but always
i must click send button to get data from server, and this is not dinamic.




And i'm now lost!




In this moment chat has two files, index.php and
getdata.php.




Files content:




index.php



=============================================















<?php



$ime = $_POST["nick"];



if (isset($ime)){



echo "




onload="getDataFromServer()">>




color="#ddaaaa"> Wellcom Qisland
Chat!





Nick: " . $ime . "



href="http://tutorials.awardspace.com/Chat/index.php"> Back





name="nickname" value="" . $ime . "">







id="speekarea" name="speekarea">




id="senddata" name="senddata" value="Send"
onClick="slanjeZahtjeva('1')">



";

}



else{



echo "






color="#ddaaaa"> Wellcom Qisland
Chat!






method="POST" id="forma1">

Enter Nick:
id="nick" name="nick" maxLength="20"
size="22">




id="submit_form" value="Uði na chat"
onClick="provjera()">";



}



echo "







";



?>



getdata.php



================================================



<?php



$var1 = $_GET["nickname"];



$var2 = $_GET["speekarea"];



if ($_GET["tip"]){



$var3 = date("H:i");



$var4 = date("Y-n-j");



$baza = mysql_connect('xxx', 'xxx', 'xxx') or die ('Server
sa bazom nije dostupan');



mysql_select_db('xxx') or die ('Greska kod spajanja na bazu
podataka');



$rez = mysql_query("insert into chat values('$var1',
'$var2', '$var3', '$var4')") or die ("Greska kod upisa u bazu (kat
veæ postoji)");



mysql_close($baza);



}



$baza = mysql_connect('xxx', 'xxx', 'xxx') or die ('Server
sa bazom nije dostupan');



mysql_select_db('xxx') or die ('Greska kod spajanja na bazu
podataka');



$rez = mysql_query('select * from chat');



$redovi = mysql_num_rows($rez);



for ($i=0; $i<$redovi; $i++){



$nick = mysql_result($rez, $i, 0);



$red = mysql_result($rez, $i, 1);



echo $nick . ": " . $red . "
";



}



mysql_close($baza);



?>



So if anybody see or know where i'm wrong...



I hope somebody know what is wrong whit this.



Thanks!



Bye!







   <<Less

Re: Ajax Chat

Posted By:   Scott_McRae  
Posted On:   Wednesday, June 21, 2006 11:10 AM

I am not sure if this is the solution that you are looking for... but I had issues with the url response being cached by IE. It was resolved by ensuring that each url request was unique by adding an unused param to the end of the url:

url = url + "&time=" + new Date().getTime();
About | Sitemap | Contact