【发布时间】:2016-11-08 13:57:12
【问题描述】:
self.addEventListener('sync', function(event) {
console.log('firing: sync');
if (event.tag == 'image-fetch') {
console.log('sync event fired');
event.waitUntil(fetchurl());
}
});
function fetchurl()
{
console.log('firing: doSomeStuff()');
/* fetch dynamic url */
fetch('https://localhost/Service-Workers-BackgroundSync/server.php')
.then(function(response) {
return response;
})
.then(function(text) {
console.log('Request successful', text);
})
.catch(function(error) {
console.log('Request failed', error);
});
}
如何在 service-worker.js 中获取动态 URL?
我正在调用“同步”事件。我想动态传递获取 URL。总是单击提交按钮我得到不同的 URL,然后我想通过“同步”事件在获取方法中传递动态 URL。
请指导我。
【问题讨论】:
标签: javascript fetch service-worker