Skip to content

Cross-browser Ajax class with CORS support and jsonP fallback.

Notifications You must be signed in to change notification settings

ssteynfaardt/Xhr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

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:https://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:https://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:https://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 )

About

Cross-browser Ajax class with CORS support and jsonP fallback.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages