Project Name | Stars | Downloads | Repos Using This | Packages Using This | Most Recent Commit | Total Releases | Latest Release | Open Issues | License | Language |
---|---|---|---|---|---|---|---|---|---|---|
Fetch Jsonp | 981 | 1,400 | 934 | 3 months ago | 19 | July 06, 2023 | JavaScript | |||
Make JSONP request like window.fetch | ||||||||||
Instagram Proxy Api | 239 | 5 years ago | JavaScript | |||||||
CORS compliant API to access Instagram's public data | ||||||||||
Mfetch | 90 | 5 years ago | mit | JavaScript | ||||||
mfetch will provide you with a strong ability to request resource management | ||||||||||
Cmn Utils | 32 | 8 | 5 | 3 years ago | 21 | February 07, 2020 | 3 | JavaScript | ||
公共函数&请求封装 | ||||||||||
Catta | 29 | 1 | 1 | 5 years ago | 11 | November 07, 2018 | mit | JavaScript | ||
Simple promise base request client for browser | ||||||||||
Intercept Fetch | 15 | 10 months ago | 2 | TypeScript | ||||||
Movie Vue | 13 | 6 years ago | Vue | |||||||
vue,vuex,vue-router,vux,vue-scroller,vue-jsonp,Muse UI等,移动端APP,API接口数据来自时光网,网易新闻,豆瓣电影等 | ||||||||||
Fetch S | 11 | a year ago | 16 | March 12, 2020 | mit | JavaScript | ||||
Fetch-based HTTP requests | ||||||||||
N Jsonp | 9 | 3 years ago | JavaScript | |||||||
❌Deprecated: This package is no longer maintained, consider using fetch() and CORS instead | ||||||||||
Parse Jsonp | 6 | 4 | 4 | 4 years ago | 3 | June 10, 2019 | 1 | isc | JavaScript | |
Get the payload of a JSONP response. |
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.
require('es6-promise').polyfill();
JSONP only supports GET method, same as fetch-jsonp
.
fetchJsonp('/users.jsonp')
.then(function(response) {
return response.json()
}).then(function(json) {
console.log('parsed json', json)
}).catch(function(ex) {
console.log('parsing failed', ex)
})
fetchJsonp('/users.jsonp', {
jsonpCallback: 'custom_callback',
})
.then(function(response) {
return response.json()
}).then(function(json) {
console.log('parsed json', json)
}).catch(function(ex) {
console.log('parsing failed', ex)
})
json_
prefixfetchJsonp('/users.jsonp', {
jsonpCallbackFunction: 'function_name_of_jsonp_response'
})
.then(function(response) {
return response.json()
}).then(function(json) {
console.log('parsed json', json)
}).catch(function(ex) {
console.log('parsing failed', ex)
})
fetchJsonp('/users.jsonp', {
timeout: 3000,
})
.then(function(response) {
return response.json()
}).then(function(json) {
console.log('parsed json', json)
}).catch(function(ex) {
console.log('parsing failed', ex)
})
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.fetchJsonp('/users.jsonp', {
jsonpCallback: 'cb'
})
The request url will be /users.jsonp?cb=jsonp_1497658186785_39551
, and the server should respond with a function like:
jsonp_1497658186785_39551(
{ ...data here... }
)
fetchJsonp('/users.jsonp', {
jsonpCallbackFunction: 'search_results'
})
The request url will be /users.jsonp?callback=search_results
, and the server should always respond with a function named search_results
like:
search_results(
{ ...data here... }
)
.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.