0.0.6 • Published 6 years ago
jsonp-get v0.0.6
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 visitparams
(object
), for example,{a: 1, b:2}
, it will make up theparameters
of url, like?a=1&b=2
callback
(string
), a key, used to pass callback function, its default value iscallback
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: "带有标签 "喜剧" 的条目"}
*/