GithubHelp home page GithubHelp logo

crossdomain-xhr's Introduction

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.

crossdomain-xhr's People

Contributors

ramahadevan avatar fgoris avatar

Watchers

James Cloos avatar Gavin avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.