AjaxRequest

AjaxRequest is a Javascript class that is designed to make it easier to make AJAX style XMLHttpRequests using javascript.

AjaxRequest simplifies things by allowing for annoymous callback handler classes to handle the various events along the AJAX request path. By looking at the request in terms of responding to the various events that are thrown, it becomes easier to abstract the usage of AJAX requests. This lets the developer use AJAX requests in a more object oriented fashion, eliminating the need for globally visible callback functions.

Test page

Example usage:
<input type="text" name="foo" onchange="update();"/>
....
function update() {
	var req = new AjaxRequest();
	req.get(
		{ 
		'url'       : "/ajax/update.action",
		'onSuccess' : updateCallback,
		'onLoading' : function () { throbber(true); },
		'onDone'    : function() { setTimeout('throbber(false);',250); }
		'params'    : {
                          'parameter1':'value',
                          'parameter2':'value',
                      }
		});
		//
		// final url= /ajax/update.action?parameter1=value¶meter2=value
}


// this could be anonymous too, but doesn't have to be...
function updateCallback(req) {  // This is the required signature for a callback
	if (req.responseXML) {
	// process xml file in javascript
	}
}

ajax.js
minimized ajax.js
Source code documentation
SourceForge project

SourceForge.net Logo

© 2005 Fourspaces Consulting, LLC
Licensed under: Apache License, Version 2.0