homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

HELP PLZZZZ - AJAX, PHP, Javascript Live Chat - Problem is how to know other session
HELP PLZZZZ - AJAX, PHP, Javascript Live Chat - Problem is how to know othe

5+ Year Member

Msg#: 4309546 posted 4:35 pm on May 8, 2011 (gmt 0)


Basically I am trying to create AJAX, PHP and Javascript supported live chat.

I am having a problem with the below:
When user write something in a textbox and sends it then this text is added to DB using AJAX and then shown on his screen using AJAX return as it is too much easy but problem is that how I will let the Admin know that any new message is received, well the admin is also connected to chat but I can update a user's screen on the event of INSERTING A MESSAGE TO DATABASE but how could I know the admin of this message. I have following idea in my mind to let the admin knows about it.

I will use javascript to run a simple AJAX script every second. That AJAX script will get the record from database and update it to the ADMIN's screen but problem is here that I read some where that contacting to database many times in a script will cause to much server load, so if I contact my database every second then it will be very harmful for my site. I have read this somewhere but I did not have self experience of this so if anyone of you can guide me then I will be very thankful to him.

I am waiting for your helpful replies.
Thanks in Advance.


JAB Creations

WebmasterWorld Senior Member jab_creations us a WebmasterWorld Top Contributor of All Time 10+ Year Member

Msg#: 4309546 posted 5:35 pm on May 9, 2011 (gmt 0)

When you're querying to see if there are new messages in the chat room from others you'll want to have the most recent row id that the client has. So if the client has message number 9001 you'll want to AJAX request to the server with the id 9001 and in PHP query if there are any messages from row 9002 or greater.

If you're using junk like innerHTML (does not properly register like anything in the DOM) you're not going to be able to reliably determine the row id's from AJAX loaded content so make sure you stick to using DOM based methods only.

Here is a great resource for working with the DOM...
http://www.howtocreate.co.uk/tutorials/javascript/domintroduction [howtocreate.co.uk]

- John

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved