Saturday 8 February 2014

A simple Chatroom powered with php and MySQL: AJAX

A I mentioned in the previous post, in this post I am going to talk about a simple chatroom I made using php and MySQL. But before talking about how that works, I need to talk a little about AJAX (Asynchronous Javascript and Xml). The basic idea behind AJAX is reloading part of a webpage without the need to reload the whole script. Let me give you an example: A good example would be several actions that you do in Facebook. Everytime you post a comment under someone's post, you see that your comments get added to the list, and that person receives a notification (if s/he is online). Both of these functionalities (commenting, and receiving a notification) are powered by AJAX technology. As you can see the whole webpage is static while you can see that notification or comment in part of the webpage (without the need for the whole page to be reloaded).

- But how does that happen?
Now even more interesting is the way this actually happens. Every couple of seconds, your computer sends a request (known as XmlHttp request) to the server  and asks the server whether there are more notifications or messages to show, and the server responds in the same way! Isn't this amazing? It is just like humans talking to each other!

But there is one more question left to ask: Can everyone send XmlHttp requests to remote server (like the one for Facebook) and get access to user's password and usernames? Or read their messages?

In the next topics I will talk about security in AJAX requests and finally the simple chatroom I made with this technology.

No comments:

Post a Comment