jsonp_p

0.0.3 • Public • Published

Build Status

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.

Dependencies (0)

    Dev Dependencies (9)

    Package Sidebar

    Install

    npm i jsonp_p

    Weekly Downloads

    0

    Version

    0.0.3

    License

    ISC

    Unpacked Size

    13.7 kB

    Total Files

    11

    Last publish

    Collaborators

    • liqt
    • liuyuchenzh