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. 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
- XMLHttpRequest is a type of javaScript object to carry on the data and request along the connection
- Layer is an example HTML element. The element have an ID “layer”. Just a place to load the output of the AJAX.
- Open is a function to open a connection to remote page.
- GET is the type of AJAX connection.
- True in Open is a declaration to use the request asynchronously.
- OnReadyStateChange triggers specified tasks whenever the AJAX status changed (fail, success, ready, etc)
- Ready State = 4 means the request was answered and already responded.
- 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 ?






high seo ranking
Awesome post about search engine optimization. I’m honestly stupefied that that hasn’t been pronounced before.
Charlotte
Just wanted to say thanks for this.
Ali Yax
good advice
borwig
Thankx for your AJAX tips
hoffel
so that’s it