The 90's called, they want their response data back.
This is a small cross-browser AJAX class with CORS support and jsonP fallback.
At only 5.3K (1.7K gzipped) Xhr is a library small enough to use on any site and bring old browsers up to date.
Do a simple get call to example.com
new Xhr().get('http:https://www.example.com');
Log the response data once the AJAX call has been successfull.
var xhr = new Xhr();
xhr.onsuccess(function(responseData,status){
console.log(responseData);
console.log(status);
});
xhr.get('http:https://www.example.com');
Xhr supports chaining methods to make writing your code so much easier.
var xhr = new Xhr().onsuccess(function(){console.log('success');}).onerror(function(){console.log('error');}).get('http:https://www.example.com');
URL
: [ STRING, required ] - URL to call
data
: [ JSON Object ] - Data to POST/PUT
callback
: [ STRING ] - Name of JsonP callback function
- head ( URL )
- options ( URL )
- get ( URL )
- put ( URL , data )
- post ( URL , data )
- delete ( URL )
- jsonp ( URL , data , callback )
function
: [ function ] - Each callback takes a function as a parameter, and will be called when the relevant state was triggered.
- onreadystatechange ( function )
- onloadstart ( function )
- onprogress ( function )
- onload ( function )
- onerror ( function )
- onsuccess ( function )
- onloadend ( function )
- ontimeout ( function )
- onabort ( function )