Gathering detailed insights and metrics for fetch-jsonp
Gathering detailed insights and metrics for fetch-jsonp
Gathering detailed insights and metrics for fetch-jsonp
Gathering detailed insights and metrics for fetch-jsonp
npm install fetch-jsonp
Allow applications to set crossorigin attribute
Published on 06 Jul 2023
Set values of options to be optional
Published on 13 Sept 2022
Add referrerPolicy support
Published on 17 Aug 2021
Add nonce support
Published on 16 Aug 2021
fix timeout ReferenceError
Published on 29 Aug 2017
Fix script error when script request error
Published on 10 Jun 2017
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
998 Stars
80 Commits
156 Forks
26 Watching
3 Branches
15 Contributors
Updated on 18 Nov 2024
JavaScript (100%)
Cumulative downloads
Total Downloads
Last day
-16.3%
17,316
Compared to previous day
Last week
22%
99,557
Compared to previous week
Last month
10%
341,038
Compared to previous month
Last year
-28.9%
3,321,538
Compared to previous year
JSONP is NOT supported in standard Fetch API, https://fetch.spec.whatwg.org.
fetch-jsonp provides you same API to fetch JSONP like native Fetch, also comes
with global fetchJsonp
function.
If you need a fetch
polyfill for old browsers, try github/fetch.
You can install with npm
.
npm install fetch-jsonp
IE8/9/10/11 does not support ES6 Promise, run this to polyfill the global environment at the beginning of your application.
1require('es6-promise').polyfill();
JSONP only supports GET method, same as fetch-jsonp
.
1fetchJsonp('/users.jsonp') 2 .then(function(response) { 3 return response.json() 4 }).then(function(json) { 5 console.log('parsed json', json) 6 }).catch(function(ex) { 7 console.log('parsing failed', ex) 8 })
1fetchJsonp('/users.jsonp', { 2 jsonpCallback: 'custom_callback', 3 }) 4 .then(function(response) { 5 return response.json() 6 }).then(function(json) { 7 console.log('parsed json', json) 8 }).catch(function(ex) { 9 console.log('parsing failed', ex) 10 })
json_
prefix1fetchJsonp('/users.jsonp', { 2 jsonpCallbackFunction: 'function_name_of_jsonp_response' 3 }) 4 .then(function(response) { 5 return response.json() 6 }).then(function(json) { 7 console.log('parsed json', json) 8 }).catch(function(ex) { 9 console.log('parsing failed', ex) 10 })
1fetchJsonp('/users.jsonp', { 2 timeout: 3000, 3 }) 4 .then(function(response) { 5 return response.json() 6 }).then(function(json) { 7 console.log('parsed json', json) 8 }).catch(function(ex) { 9 console.log('parsing failed', ex) 10 })
jsonpCallback
and jsonpCallbackFunction
There two functions can easily be confused with each other, but there is a clear distinction.
Default values are
jsonpCallback
, default value is callback
. It's the name of the callback parameterjsonpCallbackFunction
, default value is null
. It's the name of the callback function. In order to make it distinct, it's a random string with jsonp_
prefix like jsonp_1497658186785_39551
. Leave it blank if it's set by the server, set it explicitly if the callback function name is fixed.1fetchJsonp('/users.jsonp', {
2 jsonpCallback: 'cb'
3})
The request url will be /users.jsonp?cb=jsonp_1497658186785_39551
, and the server should respond with a function like:
1jsonp_1497658186785_39551( 2 { ...data here... } 3)
1fetchJsonp('/users.jsonp', {
2 jsonpCallbackFunction: 'search_results'
3})
The request url will be /users.jsonp?callback=search_results
, and the server should always respond with a function named search_results
like:
1search_results( 2 { ...data here... } 3)
.then(function(response) { return response.json(); })
in order to keep consistent with Fetch API.Uncaught SyntaxError: Unexpected token :
errorMore than likely, you are calling a JSON api, which does not support JSONP. The difference is that JSON api responds with an object like {"data": 123}
and will throw the error above when being executed as a function. On the other hand, JSONP will respond with a function wrapped object like jsonp_123132({data: 123})
.
Latest ✔ | Latest ✔ | 8+ ✔ | Latest ✔ | 6.1+ ✔ |
MIT
Thanks to github/fetch for bring Fetch to old browsers.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
Found 8/22 approved changesets -- score normalized to 3
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
license file not detected
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More@financial-times/o-fetch-jsonp
**o-fetch-jsonp is deprecated. Use the `fetch` [polyfill](http://polyfill.io/) and [Cross-Origin Resource Sharing](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS) instead.**
@alicloud/fetcher
类似 axios,封装 fetch/jsonp,可以加拦截器
fetch-jsonp-es6
Fetch JSONP like a boss using Fetch API
jsonp
A sane JSONP implementation.