Free simple AJAX library is an extremely light weight AJAX library with which you can make an AJAX call with only one line of code. Size: The size of the library is only 3 KB. Download:...
Save to:

Simple AJAX Library

Free simple AJAX library is an extremely light weight AJAX library with which you can make an AJAX call with only one line of code.

Size:
The size of the library is only 3 KB.

Download:
Download Simple AJAX Library

Usage:
You need to initiate an object of the Ajax class. The Ajax requires four parameters.

var AjaxObject = new Ajax([string] URL, [string] Method,  [string] Parameters, [string] Callback function, [string] Type of data returned);

  • URL, is the URL string to which you want to make either GET or POST Ajax request. A sample string is “actions/login.php”.
  • Method is the type of method by which you want to send data. This can be either “GET” or “POST”. If you want to send a large amount of data, I recommend using “POST” method.
  • Parameters is the string containing the parameters to be sent to the server. Whether you choose, GET or POST method, the syntax of sending the parameters is same. For example, “username=waseem&password=khan”
  • Callback function is the name of the function which will be called when the data is returned from the server via the AJAX call. Please note that you must only write the name of the function like “sampleFunction” with out the parenthesis like “sampleFunction()” else it will not work. Then you have to define this function somewhere, preferably after the AJAX call. This function will accept one parameter which is the data returned from the server. An example of such a function is:
    function sampleResponseFunction(retunedData)
    {
    // do something here with the retunedData
    }
  • Type of data returned is the last parameter, this specifies the type of data you want to be returned via the AJAX. You can set it to either, “Text” or “XML”. The data type of the callback function parameter will be the either plain text or XML format.

Sample code to make an AJAX call using the Simple AJAX library is as below:

<script type="text/javascript" language="javascript" src="../ajax.lib.js"></script>
<script type="text/javascript" language="javascript">

var ajax = new Ajax("ajax.server.php", "POST", "name=khan", seeTheResponse, "Text");
function seeTheResponse(response)
{
	alert(response);
}

</script>

If you have any difficulty using the library or have found any bug, please comment in the comment box. Thank you!

Leave a Reply