I'm currently creating an AJAX shoutbox using JavaScript and PHP. I was wondering what's the best way to build it.
I was thinking of storing a last shout ID in JavaScript and use it in the AJAX request to the PHP file:
shoutbox.php?last=21
If it is the last message then the PHP file would output nothing.
Otherwise if there were 23 shouts stored on the server for example, it would output the following XML:
xml Code:
Original
- xml Code |
|
|
|
<newshouts>
<shout>
<author>Bob</author>
<message>Hello.</message>
</shout>
<shout>
<author>Steve</author>
<message>Sup.</message>
</shout>
</newshouts>
Then in the JavaScript I would need to retrieve this data and add it to the shoutbox.
I would also need to remove the oldest two messages in the shoutbox because I want a certain number of shouts in the shoutbox at once.
Is this a good way to do it or is there a better/more efficient way of doing it?
If this is a good way I would like some help on writing the JavaScript code for it, especially removing the old messages from the shoutbox after adding new ones.
Thanks so much for you help.