php - XMLHttpRequest within service worker -
i'm trying create push notification system on chrome. have php fetches data mysql , echoes json, i'd call function getjsoncode() it's activated when push notification arrives , reads json data.
within service worker i've created standards functions. problem when create getjsoncode xmlhttprequest tells me it's not defined
self.addeventlistener('install', function(event) { self.skipwaiting(); console.log('installed', event); }); self.addeventlistener('activate', function(event) { console.log('activated', event); }); self.addeventlistener('push', function(event) { console.log('push message', event); getjsoncode(); ); }) getjsoncode() { coderequest= new xmlhttprequest(); coderequest.open('get', 'myfilewithjson.php', true); coderequest.send(); datajson = coderequest.responsetext; console.log('rispostajson'); }
is possible call external file within service worker or there kind of limitations? because don't why isn't working
instead of xmlhttprequest
, can use new fetch api. xmlhttprequest
has been deprecated , not available in service worker scope.
there's example of want achieve in this serviceworker cookbook recipe.
Comments
Post a Comment