jsonp_p
v0.0.3
Published
Promise based jsonp
Downloads
1
Readme
jsonp_p
Jsonp in Promise and callback mode.
Installing
npm install jsonp_p
Usage
import jsonp from "jsonp_p";
// Promise mode
jsonp({
url: "http://jsfiddle.net/echo/jsonp/",
params: {
name: "jsonp_p",
version: "0.0.1"
},
callback: "jsonp"
}).then(data => {
console.log(data);
//{name: 'jsonp_p',version: '0.0.1'}
});
// callback mode
jsonp({
url: "http://jsfiddle.net/echo/jsonp/",
params: {
name: "jsonp_p",
version: "0.0.1"
},
callback: "jsonp",
onSuccess(data) {
console.log(data);
//{name: 'jsonp_p',version: '0.0.1'}
}
});
options
url
type url = string;
request url
[params]
type params = object;
query string defaultencodeURI
[callback]
type callback = string;
callback name
[timeout]
type timeout = number;
[onSuccess]
type onSuccess = (res: object) => any;
If callback mode is preferred, then a function can be passed to onSuccess
[onError]
type onError = (err: Error) => any;
Just like onSuccess, available if callback mode is preferred
Callback and Promise
jsonp_p
supports callback mode now.
If a global Promise
is available, jsonp_p
can also run in Promise mode.
If your environment doesn't support Promise
, you can add polyfill.