Class o2.AjaxController
An AJAX Controller. Registers itself to AjaxState Observable upon construction.
Implements the Observer interface.
class
o2.AjaxController
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() {
}
});
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();
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() {
}
});
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.
data
- parameters passed from the Observable
to this Observer.