I'm attempting to make a very simple 2-person chatroom for my Django site. I'm learning AJAX to do this. I need parts of the web page to update without user interaction:
What is the simplest way to implement this? Is it just to use JavaScript to poll the server at regular intervals? If so, what is the best practice for doing this? I found a few solutions about using setInterval or setTimeout, but wasn't sure if this was the best way.
(I've read about reverse AJAX, but from what I've read this is more complex to implement. I don't need my solution to be fast or scalable; I just need it to work.)
Since you said you don't care for Comet, which is admittedly not very easy to get going, setInterval will do the trick. You want to be smart about it, though. You should probably start with an interval of 30 seconds. If the user starts chatting, your interval should drop down to 5. As you notice less and less action, your timer should decay down to 30 seconds again, and so on. It's not going to win any awards at a scalability convention, but it will get it done for your average mid-size website.
For more on this technique, check out this related question.