Skip to content

eBay/crossdomain-xhr

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

crossdomain-xhr

Summary

crossdomain-xhr, is a client-side javascript library with no external dependencies. This library solves the problem of cross-domain HttpRequest by utilizing the standard XMLHttpRequest. Based on the system setup, this library can leverage either CORS or IFrame PostMessage. For IE 8 & 9 support, it is recommended to use IFrame PostMessage.

===

Features

  • Simplicity - Maintains the standard jQuery Ajax API signature model for invoking Ajax Requests.
  • No External dependencies - Plain vanilla JS.
  • Ability to pick and choose between CORS or PostMessage.
  • Browser support for PostMessage is well covered.

==

Installation

bower install -g crossdomain-xhr

===

Usage

The following example uses "CORS" with polyfill "PostMessage".

cXHR.config.set( {'useCORSPolyfill' : true, 'allowedOrigins' : '*', 'sifrGateway' : 'sifr.html'}); /**Prepare cXHR with default config **/

var settings = {"clientid":"Sample Client Id", "dataType" : "json", "headers" : {"Accept" : "application/json"}};
cXHR.ajax.GET(url, settings, onSuccess, onError);

/*** Success Callback will be called if the service execution returns 200 ***/
function onSuccess(status, successResponse, xhr){

}

/*** Error Callback will be raised when network Failiure | TimeOut | Incompatible Execution | Service Exception ***/
function onError(status, errorResponse, xhr){

}

Name Type Description
url String A string containing the URL to which the request is sent.
settings Plain JSON Object{} A set of key/value pairs to configure the Ajax request. [Optional]
onSuccess Callback Function A callback function executes onSuccessful Ajax request.
onError Callback Function A callback function executes when ajax request errors.

===

Browser Distribution

CORS *IE 10+

CORS Supported Browsers

PostMessage *IE 8+

PostMessage Supported Browsers

**Browser icons proudly stolen from https://github.com/alrra/browser-logos

Contribution

Pull Requests are welcome. Please submit Github issues for any feature enhancements, bugs or documentation problems.

About

No description, website, or topics provided.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published