JSONP is NOT supported in standard Fetch API, https://fetch.spec.whatwg.org.
fetch-jsonp provides you same API to fetch JSONP like naive Fetch, also comes
with global fetchJsonp
function.
If you need a fetch
polyfill for old browsers, try github/fetch.
Installation
You can install with npm
.
npm install fetch-jsonp
Promise Polyfill for IE
IE8/9/10/11 does not support ES6 Promise, run this to polyfill the global environment at the beginning of your application.
;
Usage
The fetch-jsonp
function supports any HTTP method. We'll focus on GET and POST
example requests.
Fetch JSONP in simple way
Set JSONP callback name, default is 'callback'
Set JSONP request timeout, default is 5000ms
Caveats
You need to call .then(function(response) { return response.json(); })
in order
to keep consistent with Fetch API.
Browser Support
![]() |
![]() |
![]() |
![]() |
![]() |
---|---|---|---|---|
Latest ✔ | Latest ✔ | 8+ ✔ | Latest ✔ | 6.1+ ✔ |
License
MIT
Acknowledgement
Thanks to github/fetch for bring Fetch to old browsers.