This is a simple XHR2 helper module for Famo.us framework.
req.get({ url: '/user/me' }).then(function(response) {
// handle response
console.log(response);
});
AjaxRequest
is using asynchronous requests and requires Q by Kris Kowal.
- Add
Q
library in your HTML header, before you loadFamo.us
. For example:
<script type="text/javascript" src="q.js"></script>
<script type="text/javascript" src="https://famo.us/lib/alameda.min.js"></script>
<script type="text/javascript" src="http://code.famo.us/famous/0.2/famous.min.js"></script>
- Pull in with
require(AjaxRequest);
- Create a new instance by passing options to
AjaxRequest
methods. Any passed options will override the defaults.
.get(options)
.post(options) // request method overrides to 'POST'
{
method: 'GET',
url: undefined,
type: undefined,
params: undefined,
timeout: 5000 // ms, before request times out
}
var ajaxRequest = require('AjaxRequest');
var req = new ajaxRequest();
req.get({ url: '/user/me' }).then(function(response) {
// handle server response
console.log(response);
}).catch(function(err) { console.log(err); }).done();
var ajaxRequest = require('AjaxRequest');
var req = new ajaxRequest();
var user = {
username: 'James',
password: 'Bond'
};
req.post({
url: '/auth/login',
type: 'application/json',
params: user,
timeout: 10000
}).then(function(response) {
// handle server response
console.log(response);
}).catch(function(err) { console.log(err); }).done();
GPLv3