https://github.com/webmodules/jsonp
A simple JSONP implementation
https://github.com/webmodules/jsonp
Last synced: 2 months ago
JSON representation
A simple JSONP implementation
- Host: GitHub
- URL: https://github.com/webmodules/jsonp
- Owner: webmodules
- Created: 2012-07-04T00:16:38.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2024-04-08T14:08:00.000Z (over 1 year ago)
- Last Synced: 2025-05-11T02:43:25.704Z (7 months ago)
- Language: JavaScript
- Homepage:
- Size: 32.2 KB
- Stars: 1,907
- Watchers: 52
- Forks: 330
- Open Issues: 30
-
Metadata Files:
- Readme: Readme.md
- Changelog: History.md
Awesome Lists containing this project
- awesome-frontend - jsonp - A simple JSONP implementation (24. 前后端交互 / 24.1 Ajax模块)
- awesome-front-end - jsonp - A simple JSONP implementation (24. 前后端交互 / 24.1 Ajax模块)
README
# jsonp
A simple JSONP implementation.
[![saucelabs][saucelabs-image]][saucelabs-url]
## Installation
Install for node.js or browserify using `npm`:
``` bash
$ npm install jsonp
```
Install for component(1) using `component`:
``` bash
$ component install LearnBoost/jsonp
```
Install for browser using `bower`:
``` bash
$ bower install jsonp
```
## API
### jsonp(url, opts, fn)
- `url` (`String`) url to fetch
- `opts` (`Object`), optional
- `param` (`String`) name of the query string parameter to specify
the callback (defaults to `callback`)
- `timeout` (`Number`) how long after a timeout error is emitted. `0` to
disable (defaults to `60000`)
- `prefix` (`String`) prefix for the global callback functions that
handle jsonp responses (defaults to `__jp`)
- `name` (`String`) name of the global callback functions that
handle jsonp responses (defaults to `prefix` + incremented counter)
- `fn` callback
The callback is called with `err, data` parameters.
If it times out, the `err` will be an `Error` object whose `message` is
`Timeout`.
Returns a function that, when called, will cancel the in-progress jsonp request
(`fn` won't be called).
## License
MIT
[saucelabs-image]: https://saucelabs.com/browser-matrix/jsonp.svg
[saucelabs-url]: https://saucelabs.com/u/jsonp