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.
Confused smile

function

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

callback function

 

Now let’s back to the topic

We will use four files.

  1. myajax.js
  2. functions.js
  3. ajax.php
  4. 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 Load

function foot();
Display Ajax Response In Footer

function 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 page

function 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/