【发布时间】:2016-09-03 21:22:55
【问题描述】:
我正在尝试在 chrome 上创建推送通知系统。 我有一个从 mysql 获取数据并回显 JSON 的 php,现在我想调用一个函数 getJsonCode(),它在推送通知到达并读取 JSON 数据时被激活。
在我的 Service Worker 中,我创建了标准函数。问题是当我使用 XMLHttpRequest 创建 getJsonCode 时,它告诉我它没有定义
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');
}
是否可以在 Service Worker 中调用这样的外部文件,或者是否存在某种限制?因为我不明白为什么这不起作用
【问题讨论】:
标签: php json push-notification google-cloud-messaging service-worker