SimplAjax is a simple JavaScript library to make AJAX calls.
Download SimplAjax, read the license and put simplajax.js in the root directory of your web server. Include it in your HTML as follows:
<script src='/simpajax.js'></script>
You need to create a SimplAjax object which you can call methods on. The currently accepted methods are start() and stop(). Note that a SimplAjax object's options are immutable. You can initialize it like this:
var simplajax = new SimplAjax(options);
Where options is an object that has at least a URL attribute. Other possible attributes are:
method-GET,POST,PUT,DELETEorHEADrequestHeaders- an object containing custom request headersusername- a username for basic HTTP authpassword- a password for basic HTTP authbody- the body for aPOSTorPUTrequestsuccess- a callback function which is called on successerror- a callback function which is called on failure
The success and error functions must be of the following signature:
function(data, statuscode, responseheaders)
This is an example of a GET request:
var getExample = new SimplAjax({
URL: '/index.html',
success: function(data, statuscode, responseHeaders) {
alert(data);
alert(statuscode);
alert(responseHeaders);
},
error: function(data, statuscode, responseHeaders) {
alert(statuscode);
}
});
Licensed under the BSD license. See LICENSE for more information.