vendredi 18 janvier 2019

fetch returns undefined error in Web notification Push

I am currently studying web notification and I stumbled in this guide. Currently everything's good but I seems to have an error in fetch() as it returns an undefined response error.

function sendSubscriptionToBackEnd(subscription) {
  return fetch('send_notification.php', {
    method: 'POST',
    headers: {
      'Content-Type': 'application/json'
    },
    body: JSON.stringify(subscription)
  }).then(function(response) {
    console.log(response);
    if (!response.ok) {
      throw new Error('Bad Status code from server');
    }
    return response.json();
  }).then(function(responseData) {
    if (!(responseData.data && responseData.data.success)) {
      throw new Error('Bad response from server.');
    }
  });
}

send_notification.php

<?php
  echo json_encode(array("response"=>"ok"));
?>

This is how it looks like when it's passed:

send_notification

enter image description here

I don't know why I'm getting no response from my send_notification. This is my whole file: https://www.mediafire.com/file/nbxe6ks3sjntjj0/push_notification2.zip/file




Aucun commentaire:

Enregistrer un commentaire