@gidw/request-js
v1.0.2
Published
HTTP request helper for the browser.
Downloads
232
Readme
RequestJs
HTTP request helper for the browser.
Wrapper around XMLHTTPRequest for maximum compatibility.
Usage
var request = RequestJs(
{
url: 'https://api.example.com/resource'
},
function (error, result) {
if (error) {
console.log('REQUEST STATUS', error.requestStatus)
console.log('STATUS CODE', error.status)
console.log('STATUS TEXT', error.statusText)
if (error.requestStatus === RequestJs.ERROR) {
// ...
} else if (error.requestStatus === RequestJs.TIMEOUT) {
// ...
}
} else {
console.log('DATA', result.data)
console.log(
'HEADER Object',
RequestJs.parseHeaders(result.headers)
)
}
}
)
if (STOP_REQUEST) request.abort()
RequestJs(
{
url: 'https://api.example.com/resource',
method: 'POST',
data: JSON.stringify({
item: 23,
content: 'abc'
})
}
)