AJAX.js

This is a JSAN-flavored library which provides a simple interface to the XMLHttpRequest javascript object.
In other words you can use it in your web pages to handle asynchronous requests and plain text or XML responses.

This library is also included in the core of the famous IntraWorld™ framework and Slim2k™ software.

Download

Current stable version is this:
AJAX-0.03.tar.gz

Demo

Work in progress.
In the meantime you can take a look at the documentation examples.

Documentation

What follows is the POD extraction from the module's source.


NAME

AJAX - A simple crossbrowser javascript interface to the AJAX technology


SYNOPSIS

  // Create a new AJAX object
  var oAJAX = new AJAX();
  // Make a call
  oAJAX.call(
      {
          uri: 'http://host.domain.tld/cgi-bin/ajax_script',
          callback: manageResponse
      },
      { param1: 'value1', param2: 'value2' }
  );
  // Manage the response
  function manageResponse( cResponse )
  {
      var oDiv = document.getElementById('myDiv');
      oDiv.innerHtml = cResponse;
  }


DESCRIPTION

This fabulous class implements an OO approach to the AJAX technology, providing methods for make asynchronous calls to a CGI from a web page via JavaScript and the XMLHttpRequest object.


METHODS

new()

Object constructor, returns a brand new AJAX object.

No parameters are requested here, so you can make multiple different calls on the same object by passing different parameters to che call() method.

call()

This public method performs the call via XMLHttpRequest to the specified server's script and returns the response.

Parameters

oProps

Structure with properties used in the call passed as an object literal.

Properties are:

uri

URI of the script to call; mandatory!

Ex.: http://host.domain.tld/cgi-bin/ajax_script

method

HTTP method to use in the call.

GET, POST, HEAD... (default is GET)

asyncronous

indicates if the function execution will continue while waiting the server response or not.

true or false (default is true)

responsetype

indicates which method use for retrieve the response.

text or xml (default is text)

callback

reference to the function to use for process the response.

rParams

List of parameters to pass to the call; optional.

You can pass an URL-escaped string, an object literal, an array or an array literal.

Returned value

cResponse

Response stuff depending on responsetype setting.

Can be plain text or XML.

_getHandle()

This private method is called by the call() method and returns the XMLHttpRequest object.


EXPORTS

When used with JSAN will export call.


EXAMPLES

  // Call without parameters:
  oAJAX.call(
      {
          uri: 'http://host.domain.tld/cgi-bin/ajax_script',
          callback: function( cText ) { alert( cText ); }
      }
  );
  // Call with parameters as object literal and XML response:
  oAJAX.call(
      {
          uri: 'http://host.domain.tld/cgi-bin/ajax_script',
          responsetype: 'xml',
          callback: function( cXml ) { alert( cXml ); }
      },
      { mode: 'xml', param1: 'value1' }
  );
  // Call with parameters as array literal and XML response:
  oAJAX.call(
      {
          uri: 'http://host.domain.tld/cgi-bin/ajax_script',
          responsetype: 'xml',
          callback: function( cXml ) { alert( cXml ); }
      },
      [ 'mode','xml','param1','value1' ]
  );
  // Call with parameters as standard array with POST method
  oAJAX.call(
      {
          method: 'POST',
          uri: 'http://host.domain.tld/cgi-bin/ajax_script',
          callback: function( cResponse ) { alert( cResponse ); }
      },
      new Array( 'param1', 'value1' )
  );
  // Call with parameters as string
  oAJAX.call(
      {
          uri: 'http://host.domain.tld/cgi-bin/ajax_script',
          callback: function( cText ) { alert( cText ); }
      },
      'param1=value1&param2=value2'
  );


SEE ALSO

Official web page at http://www.sabadelli.it/edoardo/projects/javascript/ajax


AUTHOR

Edoardo Sabadelli - http://www.sabadelli.it/edoardo


COPYRIGHT

Copyright (c) 2006-2007 Edoardo Sabadelli. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the terms of the Artistic license.


Note:
XHTML validation on this page may fail due to the POD documentation inclusion, which can have some problems with the markup.