a jsonp fetch polyfill
npm install fetch-jsonp-polyfillJSONP is NOT supported in standard Fetch API.If you are sleepy for such a problem, please use this Polyfill.
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',
})
``!Chrome | !Firefox | !IE | !Opera | !Safari
--- | --- | --- | --- | --- |
Latest ✔ | Latest ✔ | 9+ ✔ | Latest ✔ | 6.1+ ✔ |
MIT