【发布时间】:2019-06-12 16:22:54
【问题描述】:
我目前正在研究网络通知,我偶然发现了this guide。目前一切都很好,但我似乎在fetch() 中有一个错误,因为它返回了一个未定义的响应错误。
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"));
?>
这是通过时的样子:
我不知道为什么我的send_notification 没有回复。这是我的整个文件:https://www.mediafire.com/file/nbxe6ks3sjntjj0/push_notification2.zip/file
---------编辑----------- 这就是我所说的未定义响应的意思。
【问题讨论】:
标签: php jquery web notifications fetch