Page 1 of 1

Updating database information output

Posted: Tue May 10, 2011 10:02 am
by Temor
Hi guys, I'm not really having an issue here, I'm just to lazy to google this.
I have a " chat " ( a very sloppy prototype of a chat, anyway ) and I store all the messages in a MySQL database. The problem with outputting straight from a database in a chat is that the user will have to refresh the page every few seconds to see if someone else left a message. To work around this I used this simple method:
<meta http-equiv='refresh' content='4'>
Problem is, this looks REALLY cheap, and also has tendencies to ruin the experience for a user ( you cant scroll down to read older messages for more than 4 seconds ). So my question is: Are there any methods you could use to " stealth-ily " update the page ( sort of like Facebook is doing with their commenting system, you just see the new comments, not the entire page refreshing which means you can read older comments without being returned to the top of the page all the time ).

Sorry for the wall of text, and thank you in advance :)

Re: Updating database information output

Posted: Tue May 10, 2011 10:04 am
by jacek
You can use javascript to get the new content and update the page, it can be a bit of a pain to get right but gives a nice result.

Google "AJAX" :D

Re: Updating database information output

Posted: Tue May 10, 2011 10:04 am
by Tino
Yes. AJAX. jQuery makes this very easy, raw JS takes a bit more code but is still relatively simple.

Re: Updating database information output

Posted: Tue May 10, 2011 10:07 am
by Temor
jacek wrote:You can use javascript to get the new content and update the page, it can be a bit of a pain to get right but gives a nice result.

Google "AJAX" :D
I tried reading a little about AJAX. It gave me a giant headache so I promised myself to never even try it. Ever.
I guess I'll have to break that promise now :(

Thanks anyway.

By the way, you should find some ajax-pro's and get them to join this forum, because I will be having a lot of questions :D

Re: Updating database information output

Posted: Tue May 10, 2011 10:09 am
by jacek
Temor wrote:By the way, you should find some ajax-pro's and get them to join this forum, because I will be having a lot of questions :D
Once you have the basics of how to use it it's really not complicated ;)

Re: Updating database information output

Posted: Tue May 10, 2011 10:10 am
by Temor
jacek wrote:
Temor wrote:By the way, you should find some ajax-pro's and get them to join this forum, because I will be having a lot of questions :D
Once you have the basics of how to use it it's really not complicated ;)
Alright. I'll give it a shot :)