If you're only looking for the concept....
1.) How will you store what was said between those users that are connected to the service? Some type of backend is required. A database would be easiest.
2.) You'll need to have your ajax script call a php script to save what each user said.
3.) After saving, you'd have to either (1) run a new request to get an update or (2) return the update after saving what the user said.
4.) When you get the response, update the view of the chat screen.
That's about it.