0.1.2 • Published 6 years ago
sync-jsonp v0.1.2
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.0to 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);
});