npm.io
3.5.0 • Published 9 years ago

ajax-promise-es6

Licence
ISC
Version
3.5.0
Deps
0
Vulns
0
Weekly
0
Stars
2

ajax-promise-es6

Promise based Ajax module for react/react-native apps.

##Installation: npm i -S ajax-promise-es6

Usage:

// default timeout is 3000ms
// url    : {type: 'string'}
// body   : {type: 'object'}
// headers: {type: 'object', optional: 'true'}

import Ajax from 'ajax-promise-es6'

Ajax.post(url, body, headers).then((res)=> {  
            console.log(res);  
  }).catch((err)=> {
      console.log(err);
  });

Ajax.get(url, body, headers).then((res)=> {  
            console.log(res);  
  }).catch((err)=> {
      console.log(err);
  });

##Example:

Ajax.post(url,
             {
                foo: 'hello',   // body data
                bar: 'there'
              },
              {
                'Cookie': 'foo=bar'  // headers
              }
    ).then((res)=> {
            // use JSON.parse(res);  
            console.log(res);  
  }).catch((err)=>{
      console.log(err);
  });

Keywords