API entry point.
It creates an new Aja object.
Example
aja().url('page.html').into('#selector').go();
Methods
(static) auth(user, passwd) → {Aja}
Setter only to add authentication credentials to the request.
Parameters:
Name | Type | Description |
---|---|---|
user |
String | the user name |
passwd |
String | the password value |
Throws:
TypeError
Returns:
chains
- Type
- Aja
(static) body(contentopt) → {Aja|String|FormData}
Request Body getter/setter.
Objects and arrays are stringified (except FormData instances)
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
content |
String | Object | Array | Boolean | Number | FormData |
<optional> |
the content value to set |
Throws:
TypeError
Returns:
chains or get the body content
- Type
- Aja | String | FormData
Example
aja().body(new FormData());
(static) cache(cacheopt) → {Aja|Boolean}
Should we force to disable browser caching (true by default) ?
By setting this to false, then a buster will be added to the requests.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
cache |
Boolean | * |
<optional> |
false means no cache (other types than booleans are casted) |
Returns:
chains or get cache value
- Type
- Aja | Boolean
Example
aja().cache(false);
(static) data(paramsopt) → {Aja|String}
URL's queryString getter/setter.
Regarding the HTTP method the data goes to the queryString or the body.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
params |
Object |
<optional> |
key/values POJO to set |
Throws:
TypeError
Returns:
chains or get the params
- Type
- Aja | String
Example
aja().data({ user : '12' });
(static) go()
Trigger the call.
This is the end of your chain loop.
Example
aja()
.url('data.json')
.on('200', function(res){
//Yeah !
})
.go();
(static) header(name, valueopt) → {Aja|String}
HTTP Request Header getter/setter.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
name |
String | the name of the header to get/set | |
value |
String |
<optional> |
the value of the header to set |
Throws:
TypeError
Returns:
chains or get the header from the given name
- Type
- Aja | String
Example
aja().header('Content-Type', 'application/json');
(static) into(selectoropt) → {Aja|Array}
Into selector getter/setter. When you want an Element to contain the response.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
selector |
String | HTMLElement |
<optional> |
the dom query selector or directly the Element |
Throws:
TypeError
Returns:
chains or get the list of found elements
- Type
- Aja | Array
Example
aja().into('div > .container');
(static) jsonPadding(paddingopt) → {Aja|String}
Padding value getter/setter, ie. the callback's name in your JSONP query.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
padding |
String |
<optional> |
a valid function name |
Throws:
TypeError
Returns:
chains or get the padding name
- Type
- Aja | String
Example
aja().jsonPadding('someFunction');
(static) jsonPaddingName(paramNameopt) → {Aja|String}
Padding name getter/setter, ie. the callback's PARAMETER name in your JSONP query.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
paramName |
String |
<optional> |
a valid parameter name |
Throws:
TypeError
Returns:
chains or get the parameter name
- Type
- Aja | String
Example
aja().jsonPaddingName('callback');
(static) method(methodopt) → {Aja|String}
HTTP method getter/setter.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
method |
String |
<optional> |
the method to set |
Throws:
TypeError if an unknown method is set
Returns:
chains or get the method
- Type
- Aja | String
Example
aja().method('post');
(static) off(name) → {Aja}
Remove ALL handlers for an event.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | the name of the event |
Returns:
chains
- Type
- Aja
Example
aja().off('success');
(static) on(name, cb) → {Aja}
Attach an handler to an event.
Calling `on` with the same eventName multiple times add callbacks: they
will all be executed.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | the name of the event to listen |
cb |
function | the callback to run once the event is triggered |
Returns:
chains
- Type
- Aja
Example
aja().on('success', function(res){ console.log('Cool', res); });
(static) queryString(paramsopt) → {Aja|String}
URL's queryString getter/setter. The parameters are ALWAYS appended to the URL.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
params |
Object | String |
<optional> |
key/values POJO or URL queryString directly to set |
Throws:
TypeError
Returns:
chains or get the params
- Type
- Aja | String
Example
aja().queryString({ user : '12' }); // ?user=12
(static) sync(syncopt) → {Aja|Boolean}
Is the request synchronous (async by default) ?
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
sync |
Boolean | * |
<optional> |
true means sync (other types than booleans are casted) |
Returns:
chains or get the sync value
- Type
- Aja | Boolean
Example
aja().sync(true);
(static) timeout(msopt) → {Aja|String}
Sets a timeout (expressed in ms) after which it will halt the request and the 'timeout' event will be fired.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
ms |
Number |
<optional> |
timeout in ms to set. It has to be an integer > 0. |
Throws:
TypeError
Returns:
chains or get the params
- Type
- Aja | String
Example
aja().timeout(1000); // Terminate the request and fire the 'timeout' event after 1s
(static) trigger(name, data) → {Aja}
Trigger an event.
This method will be called hardly ever outside Aja itself,
but there is edge cases where it can be useful.
Parameters:
Name | Type | Description |
---|---|---|
name |
String | the name of the event to trigger |
data |
* | arguments given to the handlers |
Returns:
chains
- Type
- Aja
Example
aja().trigger('error', new Error('Emergency alert'));
(static) type(typeopt) → {Aja|String}
Type getter/setter: one of the predefined request type.
The supported types are :
['html', 'json', 'jsonp', 'script', 'style']. If not set, the default type is deduced regarding the context, but goes to json otherwise.
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
type |
String |
<optional> |
the type to set |
Throws:
TypeError if an unknown type is set
Returns:
chains or get the type
- Type
- Aja | String
Example
aja().type('json');
(static) url(urlopt) → {Aja|String}
URL getter/setter: where your request goes.
All URL formats are supported:
[protocol:][//][user[:passwd]@][host.tld]/path[?query][#hash].
Parameters:
Name | Type | Attributes | Description |
---|---|---|---|
url |
String |
<optional> |
the url to set |
Throws:
TypeError
Returns:
chains or get the URL
- Type
- Aja | String
Example
aja().url('bestlib?pattern=aja');