How to make a JSONP request inside a Service Worker?
As you may know, a Service Worker doesn't have document
. Therefore many javascript approaches like this one don't work.
I need to make a JSONP request because the Blogger API doesn't answer requests from different domains using CORS.
Thank you for your response.
The Web Worker global has a method called importScripts, which you can use to include script urls.
So just define a callback function, use the function name as the callback
url parameter and pass the url to importScripts
webworker.js
function cb(data){
console.log(data);
}
importScripts('http://example.com/jsonp.php?callback=cb');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With