gpt4 book ai didi

javascript - Service Worker html 响应未显示在浏览器上

转载 作者:行者123 更新时间:2023-12-03 01:54:58 24 4
gpt4 key购买 nike

我正在尝试使用 html 回复来响应服务工作线程事件,但在浏览器上没有得到任何输出。我不明白为什么。这是我的代码。

self.addEventListener('fetch', function(event) {

event.respondWith
{
new Response("<h1>Hello!</h1>", {
headers: {'Content-Type': 'text/html'}
})};
});

最佳答案

Respondwith 是一个函数。应使用括号中的参数 func(params) 进行调用,如下所示

event.respondWith( new Response("<h1>Hello!</h1>", {
headers: {'Content-Type': 'text/html'}
}))

关于javascript - Service Worker html 响应未显示在浏览器上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50281877/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com