javascript – 服务工作者和AJAX

前端之家收集整理的这篇文章主要介绍了javascript – 服务工作者和AJAX前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试使用 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会在服务工作者上发出此错误

sw.js:39未捕获的ReferenceError:未定义XMLHttpRequest

解决方法

XMLHttpRequest已被弃用,并且在Service Worker范围内不可用.您可以使用 Fetch API而不是XMLHttpRequest.
原文链接:https://www.f2er.com/ajax/159021.html

猜你在找的Ajax相关文章