jx
v0.1.3
Published
simple ajax client
Downloads
8
Readme
jx
Simple XMLHTTPRequest wrapper.
##Installation
npm install jx
Usage:
##GET
var request = jx.get('/api/some/url/');
request.success(function(response, request) {
console.log(response);
});
request.error(function(response, request) {
console.log(response);
console.log(request);
});
##POST
var request = jx.post('/api/some/url/', data);
request.success(function(response, request) {
console.log(response);
});
request.error(function(response, request) {
console.log(response);
console.log(request);
});
##PATCH
var request = jx.patch('/api/some/url/', data);
request.success(function(response, request) {
console.log(response);
});
request.error(function(response, request) {
console.log(response);
console.log(request);
});
##DELETE
var request = jx.delete('/api/some/url/');
request.success(function(response, request) {
console.log(response);
});
.error(function(response, request) {
console.log(response);
console.log(request);
});
##Additional methods:
- jx.json.get - (url)
- jx.json.post - (url, data)
- jx.json.patch - (url, data)
jx.json methods add an 'application/json' content-type header for all requests. POST/PATCH methods call JSON.stringify on the passed data parameter before sending, and callbacks receive parsed json and the request (json, request) as parameters.