1.1.5 • Published 6 years ago

fetch-jsonp-polyfill v1.1.5

Weekly downloads
6
License
MIT
Repository
-
Last release
6 years ago

fetch-jsonp-polyfill

JSONP is NOT supported in standard Fetch API.If you are sleepy for such a problem, please use this Polyfill.

Installation

You can install with npm.

npm install fetch-jsonp-polyfill --save-dev

Notice

He can be compatible with almost all current jsonp polyfills, includinghttps://github.com/github/fetch https://github.com/matthew-andrews/isomorphic-fetch https://github.com/bitinn/node-fetch and many more.

Please note that they must be imported after them.

require('isomorphic-fetch');
require('fetch-jsonp-polyfill');

Usage

You don't need to make any changes, just modify the method:'GET' to method:'JSONP'. In this way, I didn't modify any native code.

var URL = 'http://jsfiddle.net/echo/jsonp/';

fetch(URL, {
    method: "JSONP"
})
.then(res => res.json())
.then(data => {
    console.log(data);
})
.catch(err => {
    console.log(err);
});

Other Options

fetch(URL, {
    method: 'JSONP',
    timeout: 5000,
    callback: 'callback',
    callbackName: 'fetchjsonp_callback',
})

Browser Support

ChromeFirefoxIEOperaSafari
Latest ✔Latest ✔9+ ✔Latest ✔6.1+ ✔

License

MIT

1.1.5

6 years ago

1.1.3

6 years ago

1.1.2

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago