Snapshot của camsong/fetch-jsonp: 1.0k★ · JavaScript. Make JSONP request like window.fetch
Tóm tắt dựng từ metadata GitHub của chính dự án — chưa có bài review TopGit. Trang sẽ tự động cập nhật khi bài review đầy đủ được xuất bản.
VÌ SAO CHƯA CÓ REVIEW
TopGit viết bài đầy đủ cho repo có nhiều sao nhất và được yêu cầu nhiều nhất. Trang này là snapshot trong thời gian chờ — xem README gốc ở tab READ ME.
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.
Installation
You can install with npm.
npm install fetch-jsonp
Promise Polyfill for IE
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();
Usage
JSONP only supports GET method, same as fetch-jsonp.
Difference between 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 parameter
jsonpCallbackFunction, 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.
1. You need to call .then(function(response) { return response.json(); }) in order to keep consistent with Fetch API.
2. Uncaught SyntaxError: Unexpected token : error
More 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}).
Browser Support
Latest ✔
Latest ✔
8+ ✔
Latest ✔
6.1+ ✔
License
MIT
Acknowledgement
Thanks to github/fetch for bring Fetch to old browsers.
TopGit chưa ghi nhận license cho camsong/fetch-jsonp. Phần lớn repo public trên GitHub là mã nguồn mở, nhưng điều khoản khác nhau từng repo — mở file LICENSE để xác nhận.
camsong/fetch-jsonp có website riêng không?
TopGit chưa ghi nhận URL trang chủ cho camsong/fetch-jsonp. Phần README ở tab phía trên thường có link demo, hoặc xem mô tả GitHub của repo.
camsong/fetch-jsonp là gì?
camsong/fetch-jsonp (camsong/fetch-jsonp) là dự án JavaScript trên GitHub. Theo mô tả gốc: Make JSONP request like window.fetch
Đọc thêm về camsong/fetch-jsonp ở đâu?
Trang TopGit này là một snapshot — tab "Readme" hiển thị nguyên văn README của repo (đã bỏ link, giữ ảnh). Repo GitHub ở github.com/camsong/fetch-jsonp là nguồn chính thức.
Đọc đầy đủ README ở tab phía trên.
fetch-jsonp có đáng để bạn bỏ thời gian?
ChatGPT, Claude và Perplexity đều đọc được trang này. Hỏi thử xem họ nghĩ gì về fetch-jsonp.