Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/jeroenvisser101/micro-xhr

A minimal framework (with IE compatibility) for AJAX requests
https://github.com/jeroenvisser101/micro-xhr

Last synced: 3 days ago
JSON representation

A minimal framework (with IE compatibility) for AJAX requests

Awesome Lists containing this project

README

        

# MicroXHR: a very small JavaScript XHR library
MicroXHR is a very small (828 bytes gzipped) library that handles AJAX request in a similar fashion as jQuery.

# Usage
## Basic usage
``` javascript
new Ajax('/path/to/something.txt')
.done(function (data, status, xhr) {
console.log('Request succeeded', data, status, xhr);
document.getElementById('target').innerHTML = data;
})
.always(function (xhr, status) {
console.log('always called', xhr, status);
})
.fail(function (xhr, status, error) {
console.log('An error has occurred', status, error);
});
```

## Working with JSON
``` javascript
new Ajax('/path/to/data.json')
.done(function (data, status, xhr) {
console.log('Request succeeded', data);
document.getElementById('target').innerHTML = data;
}, 'json')
.always(function (xhr, status) {
console.log('always called', xhr, status);
})
.fail(function (xhr, status, error) {
console.log('An error has occurred', status, error);
});
```