fetch-jsonp-polyfill支持 jsonp 的Fetch polyfill

联合创作 · 2023-09-30 20:38

fetch-jsonp-polyfill 是对原生 Fetch API 的扩展,使之支持 jsonp。

下载地址 https://github.com/fetch-extras/fetch-jsonp-polyfill

 

几乎所有主流的 jsonp polyfill 库兼容,如https://github.com/github/fetchhttps://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',
})

 

浏览器支持

Chrome Firefox IE Opera Safari
Latest ✔ Latest ✔ 9+ ✔ Latest ✔ 6.1+ ✔
浏览 4
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报
评论
图片
表情
推荐
点赞
评论
收藏
分享

手机扫一扫分享

编辑
举报