Creating a chat feature with JQuery?

Creating a chat feature with JQuery?

I need to make a chat feature in my website and would like to know how to do it using only HTML, CSS, JS/JQ, SQL and PHP.

How would it work? Would the server contact the user when a new message has been posted, or would the user have to constantly make requests to the server to check if it has been updated?

What's the best way to do this kind of thing, and keeping in mind to not overload the server in case there are many separate chat rooms, each with many users.

At the moment I am thinking to use Ajax to check a database to see if there are any new messages. Not sure if this is possible or a good idea.

How do other websites do this kind of thing?