0.0.6 • Published 6 years ago

jsonp-get v0.0.6

Weekly downloads
35
License
MIT
Repository
-
Last release
6 years ago

jsonpGet

A simple lib for Jsonp Cross-domain Request, it returns a promise

Installation

install by using npm:

$ npm install jsonp-get

Usage

jsonpGet(url, params?, callback?)

  • url (string), the address we want to visit
  • params (object), for example, {a: 1, b:2}, it will make up the parameters of url, like ?a=1&b=2
  • callback (string), a key, used to pass callback function, its default value is callback

demo

get data from douban api

import jsonpGet from 'jsonp-get'

let url = 'https://api.douban.com/v2/movie/search'
let params = { tag: '喜剧' }

jsonpGet(url, params)
  .then(res => {
    console.log(res)
  })
  .catch(err => {
    console.log(err)
  })

/* Network
*
* Request URL: https://api.douban.com/v2/movie/search?tag=%E5%96%9C%E5%89%A7&callback=myback
* Request Method: GET
* Status Code: 200 OK
*/

/* Console
*
*  {count: 20, start: 0, total: 200, subjects: Array(20), title: "带有标签 "喜剧" 的条目"}
*/
0.0.6

6 years ago

0.0.5

6 years ago

0.0.4

6 years ago

0.0.3

6 years ago

0.0.2

6 years ago

0.0.1

6 years ago