what JavaScript lib do you use? jQuery? ... what errors do occur?
How do i use setTimeout for a chat system
Collapse
X
-
-
... if it's not working then somwhere has to be an error. so lets start to trace that down together. you start with:
Code:$(document).ready(function() { timestamp = 0; updateMsg(); $("form#chatform").submit(function() { $.post("db.php", { message: $("#msg").val(), name: $("#name").val(), action: "postmsg", time: timestamp }, function(data) { $("#msg").empty(); addMessages(data); }); return false; }); });
Comment
-
Hey gits
I changed again to return an xml response now i want to know where to place the setTimeout
Code:function addMessages() { //alert($("#msg").val()); $.ajax({ url:"db.php", type:"post", data:"message="+$("#msg").val(), datatype:"xml", success:function(data) { $("#t1").prepend('<tr><td>bullet</td><td>reply</td><td>'+$("time",data).text()+'</td><td>De</td><td>A</td><td>'+$("message",data).text()+'</td><td>Gr</td></tr>'); } }); } function updateMsg() { $.ajax({ url:"db.php", type:"post", datatype:"xml", success:function(data) { addMessages(); } }); }
Comment
-
Hi Gits
HELP ME
I am going crazy
take a look at the code and tell me what do you think
Can you test it please because if it doesnt work i will kill myself
Code:$(document).ready(function() { updateMessages(); }) function addMessages() { $.ajax({ url:"db.php", type:"post", data:"message="+$("#msg").val()+"&action="+"post", success:function() { updateMessages(); } }); } function updateMessages() { $.ajax({ url:"db.php", type:"post", data:"action="+"update", datatype:"xml", success:function(data) { $("#t1").prepend('<tr><td>bullet</td><td>reply</td><td>'+$("time",data).text()+'</td><td>De</td><td>A</td><td>'+$("message",data).text()+'</td><td>Gr</td></tr>'); } }); setTimeout("updateMessages",7000); }
Comment
-
Comment
-
ok i'm simply confused now. lets have a look at your latest code (i guess you use the code from post #21), since that is the latest thing that is to follow at the moment. when the doc is ready you call updateMessages( ) which itself should call updateMessages( ) after 7secs again but you have a syntax error here:
Code:setTimeout("updateMessages", 7000);
Code:setTimeout(updateMessages, 7000);
and what do you mean with 2 pages? this is the first time you mention that it isn't just one?Comment
-
Hey Gits
I want to achieve chatting between 2 clients so this is why i am using setTimeout
I want when i write a message on one page it appears on the 2 pages
If you have other questions this is my email [edit]removed[edit]
bacause i want to solve this problemComment
-
please don't post email-addresses in the technical forums, or do you want to get spammed? :) ... and at least it is against the posting rules.
to the problem: i think i don't get it quite well, let me summarize:
- you have written a webclient for a webchat-application
- you open it and log in as User A
- you are able to post msg and see the messages at this page?
-> that is the code that i saw until now ...
- now you open another page and open the client again
- you login with another user B
- here is the problem? what is not working? i don't understand what the timeout should have to do with that ... since both of the windows should use the same code?Comment
-
Hi Gits
sorry i must have forgotten the rules
yes this is what i do
yes when i login with another user there is lag in time between messagesComment
-
Hey Gits the problem is that the message don't appear on same pages at the same time
I want it to appear as if both clients are chatting when i send from one page last messages appear on both pages
This is the problemComment
Comment