支持 jsonp 的Fetch polyfill fetch-jsonp-polyfill

码农软件 · 软件分类 · 其他开发相关 · 2019-10-16 18:56:37

软件介绍

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+ ✔

本文地址:https://codercto.com/soft/d/16904.html

咨询的奥秘

咨询的奥秘

[美] 杰拉尔德·温伯格(Gerald M.Weinberg) / 李彤、关山松 / 清华大学出版社 / 2004 / 29.00元

一起来看看 《咨询的奥秘》 这本书的介绍吧!

HTML 压缩/解压工具
HTML 压缩/解压工具

在线压缩/解压 HTML 代码

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具