A very minimalistic AJAX implementation that returns promise instead of relying in callbacks.
Methods
(static) ajax(url, optionsopt, methodopt) → {Promise}
A function to perform ajax requests. It returns promise instead of relying on callbacks.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
url |
String
|
Resource url | ||
options |
Object
|
<optional> |
{responseType: 'json'} | Options to apply for the ajax request |
method |
String
|
<optional> |
'GET' | Type of HTTP request (defaults to GET) |
Returns:
- Type:
-
Promise
The Promise that resolves on ajax success
Example
ATV.Ajax('http://api.mymovieapp.com/movies')
.then((response) => // do something with the response)
.catch((error) => // catch errors )
(static) del(url, optionsopt) → {Promise}
Perform an ajax request using HTTP DELETE
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
url |
string
|
Resource url | ||
options |
Object
|
<optional> |
defaults
|
Ajax options |
Returns:
- Type:
-
Promise
The Promise that resolves on ajax success
(static) get(url, optionsopt) → {Promise}
Perform an ajax request using HTTP GET
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
url |
string
|
Resource url | ||
options |
Object
|
<optional> |
defaults
|
Ajax options |
Returns:
- Type:
-
Promise
The Promise that resolves on ajax success
Example
ATV.Ajax.get('http://api.mymovieapp.com/movies')
.then((response) => // do something with the response)
.catch((error) => // catch errors )
(static) post(url, optionsopt) → {Promise}
Perform an ajax request using HTTP POST
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
url |
string
|
Resource url | ||
options |
Object
|
<optional> |
defaults
|
Ajax options |
Returns:
- Type:
-
Promise
The Promise that resolves on ajax success
Example
ATV.Ajax.post('http://api.mymovieapp.com/movies', {data})
.then((response) => // do something with the response)
.catch((error) => // catch errors )