【问题标题】:Chrome Push Notifications with XHR(using JavaScript without PHP)带有 XHR 的 Chrome 推送通知(使用没有 PHP 的 JavaScript)
【发布时间】:2016-04-15 13:03:27
【问题描述】:

请解释如何使用 XHR 和 Javascript 进行推送通知。

我在 XHR 和 PHP 的帮助下完成了推送通知,但我想知道如何仅使用 javascript 通过 AJAX 请求推送通知

我总是收到错误代码 401 或 400,代码如下:

$.ajax({
  url: "https://android.googleapis.com/gcm/send",
  type: "POST",
  beforeSend: function(xhr){
    xhr.setRequestHeader('Authorization','key=API_KEY');
    xhr.setRequestHeader('Content-Type', 'application/json');
  },
  registration_ids: [
    "SUBSCRIPTION_ENDPOINTS"
  ],
  payload: {
    data:{
      "score":"50"
    }
  },
  success: function (data) {
    console.log(data);
  },
  error: function(error) {
    console.log(error);
  }
});

【问题讨论】:

  • 我认为 gcm 仅适用于服务器。客户端推送没有任何意义。

标签: javascript jquery ajax push-notification


【解决方案1】:

您可以通过请求“AJAX 跨域请求”或“CORS”在 Google 中显示您的问题的答案。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-04-04
    • 2016-04-15
    • 2017-11-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-05-31
    • 2017-08-02
    相关资源
    最近更新 更多