Dasar-dasar AJAX (3)
Posted by argonzdcc on April 18, 2011
In this series of the article I’m trying to write in English. Apart telling you the continuation of the last article, I’m also learning English writing by doing in fun. Well guys..! as the last article we talked about XMLHttpReques and some stuff that following the object. Now I will try to write snippet code of AJAX and then I will explain about the codes. So we could know it deeply. Here we go..!
LearnAjax.html

Explanation :
LearnAjax.html is the file which is to be opened for the first time and load the function AjaxFunction from learnAjax.js
LearnAjax.js

Explanation :
When LearnAjax.html is opened then LearnAjax.js also include to be executed. In this case when the page load then function AjaxFunction is executed. In AjaxFunction at line 2, xmlhttp is a variable which is contain value from function called GetXmlHttpObject() where we create the XMLHttpRequest. Variable url contain the php file which is the target of request. And then we add variable sid to the url which mean the url will containt address with session id in random value.
We access the event onreadystatechange to trigger when the state is change then stateChange function will be executed. stateChange function contain conditional if the property readyState is 4 then the responseText property which is contain the response from server and to be placed on document elemant with id txtHint and the data will be displayed on div id txtHint.
LearnAjax.php

Explanation
This is the server-side scripting. This php file is the target of request from client-side scipting.
If you have problem with those codes, feel free to ask me. Well guys, this just a basic AJAX application, I will try to write the interesting AJAX application in the next article. So wait for the next article. Thanks to visit my weblog !
