0.2.3 • Published 8 years ago
jsonp2 v0.2.3
jsonp2
A tiny patch for original jsonp.
A simple JSONP implementation. (Promise optional)
Installation
Install for node.js or browserify using npm:
$ npm install jsonp2API
jsonp(url, opts, fn)
url(String) url to fetchopts(Object), optionalparam(String) name of the query string parameter to specify the callback (defaults tocallback)timeout(Number) how long after a timeout error is emitted.0to disable (defaults to60000)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 toprefix+ incremented counter)
fncallback
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).
Just a tiny patch for original jsonp repo.
If fn callback isn't passed into jsonp, it will return a Promise.
The original jsonp return will be replaced by a Promise instance.
jsonp(url, opts); // return a promise.
jsonp(url, opts).then((data) => {}).catch((err)=>{})If fn parameter is passed in, everything are still running like original jsonp module.
License
MIT