sync-jsonp
v0.1.2
Published
sync jsonp for web
Downloads
49
Readme
sync-jsonp
安装
npm install sync-jsonp --save
使用
import syncJsonp from 'sync-jsonp'
api
syncJsonp(url, data, opts): Promise
url
(string) url to fetchdata
(object) send param, optionalopts
(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.0
to 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)
example
import syncJsonp from 'sync-jsonp';
syncJsonp('http://hostname.com/path/to/api').then((data) => {
console.log(data);
});
syncJsonp('http://hostname.com/path/to/api', {
t: +new Date()
}).then((data) => {
console.log(data);
});
syncJsonp('http://hostname.com/path/to/api', undefined, {
timeout: 2000
}).then((data) => {
console.log(data);
});