The teeny tiny cross-browser XHR library - just 493 bytes gzipped!
MIT License
#µXHR
The teeny tiny cross-browser XHR library - just 493 bytes gzipped!
##Usage
// with a data object
uxhr('endpoint.html', {
foo: 'bar',
baz: 5
}, {
complete: function (response) { ... }
});
// ... or with a data string
uxhr('endpoint.html', 'war=peace&freedom=slavery&ignorance=strength', {
complete: function (response) { ... }
});
// abort a request
var req = uxhr('endpoint.html', {
complete: function (response) { ... }
});
req.abort();
##Arguments
Argument | Type | Required |
---|---|---|
url | String | Yes |
data | Object | No |
options | Object | No |
##Options
Option | Type | Default | Notes |
---|---|---|---|
method | String | GET |
GET , POST , HEAD , PUT , DELETE , etc. see wikipedia.org/wiki/HTTP#Request_methods
|
headers | Object | {} |
Custom headers for this request, see wikipedia.org/wiki/List_of_HTTP_header_fields#Requests |
sync | Boolean | false | Should this request be synchronous? |
timeout | Number | 0 |
Timeout (in ms) before aborting the request |
complete | Function | function(){} |
Callback fired when the request is completed |
success | Function | function(){} |
Callback fired when the request is completed successfully (eg. with HTTP status code < 400) |
error | Function | function(){} |
Callback fired when the request returns an error (eg. HTTP status code >= 400) |
##Returns
uxhr
returns the request object