gpt4 book ai didi

javascript - Service Worker 和 AJAX

转载 作者:可可西里 更新时间:2023-11-01 02:36:51 26 4
gpt4 key购买 nike

我正在尝试使用 AJAX 来检索我想在用户端显示的推送通知的详细信息,但它还不起作用。

/*
*
* Push Notifications codelab
* Copyright 2015 Google Inc. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License
*
*/

// Version 0.1

//'use strict';

console.log('Started', self);

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);

var title = 'Push message';
var xhttp = new XMLHttpRequest();

xhttp.open("GET", "https://www.domain.nl/devtest/1.php", false);
xhttp.send();
title = xhttp.responseText;

event.waitUntil(
self.registration.showNotification(data, {
'body': 'The Message',
'icon': 'images/icon.png'
})
);
});

当我使用 GCM 向客户端发送推送通知时,Chrome 在服务 worker 上给出了这个错误:

sw.js:39 Uncaught ReferenceError: XMLHttpRequest is not defined

最佳答案

XMLHttpRequest 已被弃用,它在 Service Worker 范围内不可用。您可以使用 Fetch API 而不是 XMLHttpRequest .

关于javascript - Service Worker 和 AJAX,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38393126/

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