Class o2.Ajax


static class o2.Ajax

A static class for making AJAX GET and POST requests.

Defined in ajax.core

Function Summary
static abort (XMLHttpRequest xhr)

Explicitly abort the request.

When the request is explicitly abourted, onaborted callback is fired.

Usage example:

 var request = o2.Ajax.get(url, params, callbacks);

 ...

 if (someCondition) {
      o2.Ajax.abort(request);
 }
 
static createXhr()

Creates a native XMLHttpRequest object.

This is a low-level function; it simply returns the browser's native object. You may most probably want to use Ajax.get or Ajax.post instead, for more functionality.

Usage example:

 // Creates a low-level cross-browser XmlHttpRequest object.
 var request = o2.Ajax.createXhr();
 
static get (String url, Object parameters, Object callbacks, Boolean isSync)

Sends and AJAX GET request.

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) {}
 });
 
static getSingle (String url, Object parameters, Object callbacks)

Sends a single AJAX GET request, and discards further requests until a response comes from the first request.

Two requests that have identical URLs and parameter name-value pairs, are considered uniqe. This method, ensures that no two unique GET requests will be fired without waiting for the other.

Usage example:

 var request = o2.Ajax.getSingle('/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) {}
 });
 
static post (String url, Object parameters, Object callbacks, Boolean isSync)

Sends an AJAX POST request.

Usage example:

 var request = o2.Ajax.post('/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) {}
 });
 
static postSingle (String url, Object parameters, Object callbacks)

Sends a single AJAX POST request, and discards further requests until a response comes from the first request.

Two requests that have identical URLs and parameter name-value pairs, are considered uniqe. This method, ensures that no two unique POST requests will be fired without waiting for the other.

Usage example:

 var request = o2.Ajax.postSingle('/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) {}
 });
 

Function Details

function abort

static abort(XMLHttpRequest xhr)

Explicitly abort the request.

When the request is explicitly abourted, onaborted callback is fired.

Usage example:

 var request = o2.Ajax.get(url, params, callbacks);

 ...

 if (someCondition) {
      o2.Ajax.abort(request);
 }
 
Parameters:
xhr - the original XMLHttpRequest being sent.

function createXhr

static createXhr()

Creates a native XMLHttpRequest object.

This is a low-level function; it simply returns the browser's native object. You may most probably want to use Ajax.get or Ajax.post instead, for more functionality.

Usage example:

 // Creates a low-level cross-browser XmlHttpRequest object.
 var request = o2.Ajax.createXhr();
 
Returns:
the created XMLHttpRequest object.

function get

static get(String url, Object parameters, Object callbacks, Boolean isSync)

Sends and AJAX GET request.

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) {}
 });
 
Parameters:
url - the URL to send the request.
parameters - parameters collection as a name/value pair object ({}).
callbacks - An object of the form {oncomplete: fn(responseText, responseXml, xhr, status), onerror: fn(status, statusText, xhr), onaborted: fn(xhr), onexception: fn(exception, originalXhr)}. Any of these callbacks are optional.
isSync - (optional defaults to false). Set this true for sending a snychronous request.
Returns:
the original XMLHttpRequest object.

function getSingle

static getSingle(String url, Object parameters, Object callbacks)

Sends a single AJAX GET request, and discards further requests until a response comes from the first request.

Two requests that have identical URLs and parameter name-value pairs, are considered uniqe. This method, ensures that no two unique GET requests will be fired without waiting for the other.

Usage example:

 var request = o2.Ajax.getSingle('/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) {}
 });
 
Parameters:
url - the URL to send the request.
parameters - parameters collection as a name/value pair object ({}).
callbacks - An object of the form {oncomplete: fn(responseText, responseXml, xhr, status), onerror: fn(status, statusText, xhr), onaborted: fn(xhr), onexception: fn(exception, originalXhr)}. Any of these callbacks are optional.
Returns:
the active XMLHttpRequest object.
See also:

function post

static post(String url, Object parameters, Object callbacks, Boolean isSync)

Sends an AJAX POST request.

Usage example:

 var request = o2.Ajax.post('/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) {}
 });
 
Parameters:
url - the URL to send the request.
parameters - parameters collection as a name/value pair object ({}).
callbacks - An object of the form {oncomplete: fn(responseText, responseXml, xhr, status), onerror: fn(status, statusText, xhr), onaborted : fn(xhr), onexception: fn(exception, originalXhr)}. Any of these callbacks are optional.
isSync - (optional defaults to false). Set this true for sending a snychronous request.
Returns:
the original XMLHttpRequest object.

function postSingle

static postSingle(String url, Object parameters, Object callbacks)

Sends a single AJAX POST request, and discards further requests until a response comes from the first request.

Two requests that have identical URLs and parameter name-value pairs, are considered uniqe. This method, ensures that no two unique POST requests will be fired without waiting for the other.

Usage example:

 var request = o2.Ajax.postSingle('/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) {}
 });
 
Parameters:
url - the URL to send the request.
parameters - parameters collection as a name/value pair object ({}).
callbacks - An object of the form {oncomplete: fn(responseText, responseXml, xhr, status), onerror: fn(status, statusText, xhr), onaborted: fn(xhr), onexception: fn(exception, originalXhr)}. Any of these callbacks are optional.
Returns:
the active XMLHttpRequest object.
See also: