Class o2.AjaxController

Implements Observer

An AJAX Controller. Registers itself to AjaxState Observable upon construction.

Implements the Observer interface.

Direct Known Subclasses:

class o2.AjaxController
Defined in ajaxcontroller.core

Constructor Summary
AjaxController (XmlHttpRequest xhr, Object args)

See http://download.oracle.com/javase/1.4.2/docs/api/java/util/Observer.html

Usage example:

 var request = o2.Ajax.get('/api.php', {
      name   : 'Volkan Özçelik',
      action : 'add'
 }, {
      oncomplete  : function(text, xml, xhr, status) {},
      onerror     : function(statusCode, statusText, xhr) {},
      onaborted   : function(xhr) {},
      onexception : function(exception, xhr) {}
 });

 // The request will time out after 5 seconds and then ontimeout
 // will be called.
 var controller = new o2.AjaxController(requrest, {
      timeout   : 5000,
      ontimeout : function() {
      }
 });
 

Function Summary
virtual unregister()

Unregisters the object from the observer.

Call this when the AJAX request completes.

o2.JsonpController overrides this implementation.

Usage example:

 var controller = new o2.AjaxController(xhr, params);

 ...

 // The o2.AjaxState no longer listens to this Controller.
 controller.unregister();
 
virtual update (Object data)

Implementation of the Observer.update interface method.

Usage example:

 var controller = new o2.AjaxController(xhr, params);

 ...

 // Timeout the AJAX request immediately.
 controller.update({isTimedOut : true});
 

o2.JsonpController overrides this implementation.

Constructor Details

constructor AjaxController

AjaxController(XmlHttpRequest xhr, Object args)

See http://download.oracle.com/javase/1.4.2/docs/api/java/util/Observer.html

Usage example:

 var request = o2.Ajax.get('/api.php', {
      name   : 'Volkan Özçelik',
      action : 'add'
 }, {
      oncomplete  : function(text, xml, xhr, status) {},
      onerror     : function(statusCode, statusText, xhr) {},
      onaborted   : function(xhr) {},
      onexception : function(exception, xhr) {}
 });

 // The request will time out after 5 seconds and then ontimeout
 // will be called.
 var controller = new o2.AjaxController(requrest, {
      timeout   : 5000,
      ontimeout : function() {
      }
 });
 
Parameters:
xhr - the original XmlHttpRequest
args - an associative array in the form {timeout:[timeoutInMilliSeconds], ontimeout: [function]} both attributes are optional.

Function Details

function unregister

virtual unregister()

Unregisters the object from the observer.

Call this when the AJAX request completes.

o2.JsonpController overrides this implementation.

Usage example:

 var controller = new o2.AjaxController(xhr, params);

 ...

 // The o2.AjaxState no longer listens to this Controller.
 controller.unregister();
 

function update

virtual update(Object data)

Implementation of the Observer.update interface method.

Usage example:

 var controller = new o2.AjaxController(xhr, params);

 ...

 // Timeout the AJAX request immediately.
 controller.update({isTimedOut : true});
 

o2.JsonpController overrides this implementation.

Parameters:
data - parameters passed from the Observable to this Observer.