npm install sync-jsonp --save
import syncJsonp from 'sync-jsonp'
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)
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);
});