fetch-jsonp-polyfill

1.1.5 • Public • Published

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

Chrome Firefox IE Opera Safari
Latest ✔ Latest ✔ 9+ ✔ Latest ✔ 6.1+ ✔

License

MIT

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 1.1.5
    22
    • latest

Version History

  • Version
    Downloads (Last 7 Days)
    • Published
  • 1.1.5
    22
  • 1.1.3
    0
  • 1.1.2
    0
  • 1.1.0
    0
  • 1.0.0
    0

Package Sidebar

Install

npm i fetch-jsonp-polyfill

Weekly Downloads

22

Version

1.1.5

License

MIT

Unpacked Size

13.5 kB

Total Files

6

Last publish

Collaborators

  • ajiemath