How AJAX Works ?

AJAX is Asynchronous JavaScript and XML. It works by pinging a desired URL with providing some data. After that, the remote URL (usually PHP file) will process your request and make a respond for you. After the respond is created, AJAX XMLHttpRequest will read the respond and sends it back to you in XML format. [...]

AJAX is Asynchronous JavaScript and XML. It works by pinging a desired URL with providing some data. After that, the remote URL (usually PHP file) will process your request and make a respond for you. After the respond is created, AJAX XMLHttpRequest will read the respond and sends it back to you in XML format. After you receive this raw XML, the next function is triggered, inject this XML data, whole or some part of it, into your HTML elements. That is simple simulation how does AJAX works.

Here is an example of calling a remote content and inject it into HTML:

<script>
ajax = new XMLHttpRequest();
layer = document.getElementById("layer");
ajax.open("GET","http://site.com/remote-page.php",true);
ajax.onreadystatechange = function () {
if (ajax.readyState==4) {
layer.innerHTML = ajax.responseBody;
}
}
ajax.send(null);
</script>

Definition

  1. XMLHttpRequest is a type of javaScript object to carry on the data and request along the connection
  2. Layer is an example HTML element. The element have an ID “layer”. Just a place to load the output of the AJAX.
  3. Open is a function to open a connection to remote page.
  4. GET is the type of AJAX connection.
  5. True in Open is a declaration to use the request asynchronously.
  6. OnReadyStateChange triggers specified tasks whenever the AJAX status changed (fail, success, ready, etc)
  7. Ready State = 4 means the request was answered and already responded.
  8. Send(null) starts the AJAX Connection. It was null because there are no data required to be send to the remote site.

That’s all, have some words to say ? :-)

Posted on ,

Bookmark and Share

One Response to “How AJAX Works ?”

  1. Awesome post about search engine optimization. I’m honestly stupefied that that hasn’t been pronounced before.

Leave a Reply


AJAX Random Post

  • Random Post For Blogger

    If you have blogger-based blog especially for you who host blog at my-blogname.blogspot.com, you must be wondering how to create random post widget for it. Some said that Blogger is not complete as Wordpress in the plugin and script. But we can handle it with little tips and trick. I'm surely inspir
  • Hide Alexa Widget

    Believe it or not Alexa has become vital comparation tool to determine the crowd of a site. The most important way is placing the Alexa Widget on the site to send records of unique IP per day to Alexa I have proven that Alexa Widget is important. One of my blog Alexa was 2.500.000 but after i put A
  • How to Get Qualified Backlinks

    Most of bloggers want to have a lot of backlinks to their sites. Backlinks always give positive impacts for sites on Google PageRank and of course on the real traffic popularity itself. There are several ways to get traffics, they are easy to achieve. You can see the description below: Use
  • 10 Reason Firefox Better Than IE

    Firefox has shown their ability to the world by competing Microsoft's Internet Explorer which always installed as default browser on every Windows OS computers. The birth of Firefox is 17 August 1945. That is the birthday of first tabbed browser which attracts people's attention and faith. Mozilla
  • MyBlogLog Avatar on Wordpress

    Have you ever imagine to put the Yahoo avatars on comments. I recently created wordpress plugin called MBLavatar (comes from mybloglog's avatar) to do it so. Check it out. You don't have to put any PHP codes, it will automatically replace all gravatars on your pages into mybloglog's or Yahoo's avat

References

Who am I ?

My name is Julian Widya Perdana. I study at University of Gadjah Mada, Yogyakarta. I am a young developer addicted in JavaScript, Plugins, Themes, AJAX, and PHP developement. If you feel satisfy with my work, please support me to keep it developed