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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -