Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

JavaScript

Samuel Altarac
Samuel Altarac
4,961 Points

AJAX server-side event listener

If I'm making a chat app, I need my browser and my friend's browser to refresh after each posted message. How can I listen for a post to mysql database so that i can refreshed the content that gets loaded into my chat app?

1 Answer

Andrew Dunn
Andrew Dunn
14,718 Points

Someone else may correct me on this, but AJAX doesn't work this way on its own. I've researched this one lots of times over the years, and haven't really come up with a viable, standards compliant solution - but apparently there are some hackish ways of getting around the limitations, such as using a hidden iframe.

Here's a wiki article on Comet (Reverse AJAX) http://en.wikipedia.org/wiki/Comet_(programming)

And here's a crazy PHP tutorial on 'pushing' an update notification to a user's browser. http://www.zeitoun.net/articles/comet_and_php/start