Created: 2012-08-21 06:24
Updated: 2015-08-12 13:54

README.md

Xhr

The 90's called, they want their response data back.

What is Xhr ?

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.

Useage

Basics

Do a simple get call to example.com

new Xhr().get('http://www.example.com');
Response

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://www.example.com');

Chaining methods

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://www.example.com');

Methods

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 )

Callbacks

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 )
Cookies help us deliver our services. By using our services, you agree to our use of cookies Learn more