ajax

ajax

Properties:
Name Type Description
encoding String

The default encoding type, default values is default

defaultDataType String

The default data type, default value is default

defaultUrl String

The default url

defaultType String

The default type, default value is GET

Access via aim.ajax - This is a simple XMLHttpRequest loading facility which has the capacity to encode, decode data utilizing the aim.encode module and also format data to and from JSON.

Methods

(private, static) addHeaders(request, headers)

Set the request headers, loops through the header array and adds each one to the request object

Parameters:
Name Type Description
request Object

The request object

headers Object

The headers object

(private, static) formatParams(data, url)

Handle the param string for the request, formats the string an decodes any URI encoding

Parameters:
Name Type Description
data Object

The parameter object

url String

The url

(private, static) formatReqData(type, data, dataType, params, encode)

Format the request data

Parameters:
Name Type Description
type Object

The type of request

data Object

The data for the request

dataType String

The data type for the request i.e. json/xml

params Object

The parameters for the request

encode String

Determines whether the request should be encoded

(private, static) handleResData(data, dataType)

Format the request data

Parameters:
Name Type Description
data Object

The request data

dataType Object

The dataType

(protected, static) send(options, scope)

Execute the ajax request

Parameters:
Name Type Description
options Object

The request options type:string, url:string, dataType:string, data:object, headers:object, complete:function, success:function, error:function

scope Object

The callback scope

0: request not initialized 1: server connection established 2: request received 3: processing request 4: request finished and response is ready 200: "OK" 404: Page not found

An Example request object call would be below AIM.Ajax.send({ // Optional Type - defaults to GET type:'GET', // Required URL, can include query parameters url:myapi.php, // Data Type for the request and response, handles either a //string or an array for independant options for the request or response dataType:'json', // Data to POST or send as a query string, parameters will be automatically parsed data:{id:1, name:2}, // Optional headers headers:'', // Optional Complete handler when the request completes readystate:function(data){}, // Optional Success handler for a successful request success:function(data){}, // Optional error handler error:function(data){}, // Optional encoding type for request and response base64 as an example, handles either a string or an array encode:'base64', }, this);