smallxhr
Very Small XHR library for easy, minimal cross-browser requests.
Usage
Basic GET
var xhr = ; // GET example.com;
Complete POST
var xhr = ; var postData = JSON; // POST example.com with data;
API
url
- The url to send the request todata
- Data to send with the request. Should be a string ornull
.callback
- Executed on success or failure with params (error, data, xhrResponse)method
- Any HTTP verbcontenttype
- Any HTTP content type (default:application/x-www-form-urlencoded
)timeout
- time in milliseconds before the request should be cancelled (default:5000
)headers
- key-value pairs for specifying extra headers to be sent (default:{}
)
Callback
error
- AnError
object with a custom attributetype
error.type
- one of'timeout'
for a timeout error, or'http'
to indicate you should check the value ofxhrResponse.statusCode
.
data
- Any data returned from the requestxhrResponse
- The XMLHttpRequest object
Installation
npm install --save smallxhr
Thanks
- Simon Doodkin's original tinyxhr gist
- Scott Duncombe's updates