Class o2.Ajax
static
class
o2.Ajax
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); }
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();
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) {} });
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) {} });
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) {} });
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); }
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();
XMLHttpRequest
object.
function get
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) {} });
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. XMLHttpRequest
object.
function getSingle
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) {} });
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. XMLHttpRequest
object.
function post
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) {} });
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. XMLHttpRequest
object.
function postSingle
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) {} });
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. XMLHttpRequest
object.
A static class for making AJAX GET and POST requests.