Simple XHR2 client for Famo.us framework
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
AjaxRequest.js
LICENSE
README.md

README.md

Famo.us-AjaxRequest

This is a simple XHR2 helper module for Famo.us framework.

req.get({ url: '/user/me' }).then(function(response) {
    // handle response
    console.log(response);
});

Getting Started

Dependency:

AjaxRequest is using asynchronous requests and requires Q by Kris Kowal.

  • Add Q library in your HTML header, before you load Famo.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>

How to load

  • Pull in with require(AjaxRequest);
  • Create a new instance by passing options to AjaxRequest methods. Any passed options will override the defaults.

Supported methods

.get(options)
.post(options)  // request method overrides to 'POST'

Default Options

{
    method: 'GET',
    url:    undefined,
    type:   undefined,
    params: undefined,
    timeout: 5000       // ms, before request times out
}

Examples

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();

License

GPLv3