The application consists of 3 "windows" / "panels":
the private chat users
the public chat users
the chat history (switchable between private and public chats)
Pretty self explanatory, right?
I have the script initialize setting default/global variables and setting up three setInterval() to update those three "windows" / "panels"... like I said it all works fine except every once in a while it is like the responseText from one of the intervals hangs up and then the interval executes 3 - 5 more times before receiving the first... so, if within this time someone has added a chat message it gets output 4 - 6 times instead of once. Or a user that joins during one of these hiccups gets added to the list 4 - 6 times... etc... you get the picture.
My question is if I am using the best solution... or if I should maybe consider another method for updating this content? I added a check on the private chat users list to make sure if they are already listed not to added them again and so it doesn't but the scripts are still executing and retrieving the content regardless of whether or not it is going to use it... and in the long run I would rather not be transporting data that is not going to be used... Basically, what I am doing is on a query I am sending the id of the last retrieved, and the PHP script only fetches and returns that which is new. So, in this case... during the "hiccup" the new is being retrieved and returned multiple times...
I have been looking into Comet, BOSH, XMPP but I am uncertain as to whether or not this will be beneficial in the long run... as to whether it would make things easier on the server or create a larger strain than necessary. I mean, if I have to work harder to just optimize my code to make sure there are no cracks for things to slip through then I would rather do that than to take, and use, an application that is pre-built, and therefore simplifies things for me, but makes things more strenuous on the server.
You could use setTimeout() instead and send another request only after the previous succesfully returns. And maybe you could add some IDs for the chat messages as well and check, whether they exist already in the document, before you output them.