AJAX - Integrate AJAX On Your Site
Integration of ajax on site is quite easy without using any toolkit. You can create your own script and call-back functions.
hummm so lets get start without wasting a time.
Before digging into code lets introduce the functions and callback function.
1. Function :
For me function is just a machine which take input and give me output.
Now in any language function works like this diagram . Format of function will be like:
myfunction(x)
{
process input y = x+5;
return y;
}
they will return a output when we call them
calling such function As
y = function(x);
2. Callback function.
callback function is the function to be executed after it get response.
its simply mean output of one function will be input of another function
Now let’s back to the topic
We will use four files.
- myajax.js
- functions.js
- ajax.php
- index.php
1.myajax.js
first javascript file which will contain ajax function .list of functions —
function createREQ(); Create Request to server . function requestGET(url, query, req); If request uses GET method . function requestPOST(url, query, req); If request uses POST method . function doCallback(callback, item) ; Which function should be use to display response. function doAjax(url, query, callback, reqtype, getxml); Main AJAX function.
Another file contains list of callback functions.
2. functions.js
function initOnLoad();
Display ajax Response On Page Loadfunction foot();
Display Ajax Response In Footerfunction left_sidebar();
Display Ajax Response In left sidebar
function right_sidebar();
Display Ajax Response In right sidebar
function getvalue();
Get the value of element in pagefunction resetValues();
Reset the values of elements
function populateComp();
Populate the company in select eg: Nokia ,samsung
(ajax response is in XML Format)
function populateModel();
populate the model of respected manufacture eg:s3500,Samsung X2-O2,Nokia 1100.
(ajax response is in XML Format)
3. index.php
This is the file in which you want to integrate AJAX.
4. ajax.php
This is the requested file, which process the request and return the response to users.
source: http://buffernow.com/integrate-ajax-on-your-site-simple-tutorial-for-beginners/