Hi guys, I am still in the path of converting my app into a PWA.
After subscribing the user to receive push messages I have to take save this information to the server into my database & this is where I am failing, I tried the code below to send the information to a function that will save into a database but the function is not receiving anything because i keep getting TypeError: expected string or buffer when i try to read the information. Is there an easier way to grab information from JavaScript function as JSON data & send it to the server?
function sendSubscriptionToBackEnd(subscription) {
method: 'POST',
url: "{{=URL(''save_data")}},
headers: {
'Content-Type': 'application/json'
},
body: JSON.stringify(subscription)
})
.then(function(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.');
}
});
}
Regards