fetch-jsonp-polyfill支持 jsonp 的Fetch polyfill
fetch-jsonp-polyfill 是对原生 Fetch API 的扩展,使之支持 jsonp。
下载地址 https://github.com/fetch-extras/fetch-jsonp-polyfill
几乎所有主流的 jsonp polyfill 库兼容,如https://github.com/github/fetch、https://github.com/matthew-andrews/isomorphic-fetch 、https://github.com/bitinn/node-fetch
安装
使用 npm
npm install fetch-jsonp-polyfill --save-dev
引用
require('isomorphic-fetch')
require('fetch-jsonp-polyfill')
or
import 'whatwg-fetch'
import 'fetch-jsonp-polyfill'
使用
fetch('http://jsfiddle.net/echo/jsonp/?hello=world', {
method: "JSONP"
})
.then(res => res.json())
.then(data => {
console.log(data);
})
.catch(err => {
console.log(err);
})
其它选项
fetch(URL, {
method: 'JSONP',
timeout: 5000,
callback: 'callback',
callbackName: 'fetchjsonp_callback',
})
浏览器支持
| Latest ✔ | Latest ✔ | 9+ ✔ | Latest ✔ | 6.1+ ✔ |
评论
