Hi,

Can you try to change the "body:" with "data:" on the code?
There is a sample JS code on the page:
https://www.digitalocean.com/community/tutorials/submitting-ajax-forms-with-jquery

By the way, it is better to check the JSON object format with
https://jsonlint.com/ or similar.

Best,
Murat.


mostwanted <godirao...@gmail.com>, 3 Oca 2022 Pzt, 10:31 tarihinde şunu
yazdı:

> 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
>
> --
> Resources:
> - http://web2py.com
> - http://web2py.com/book (Documentation)
> - http://github.com/web2py/web2py (Source code)
> - https://code.google.com/p/web2py/issues/list (Report Issues)
> ---
> You received this message because you are subscribed to the Google Groups
> "web2py-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to web2py+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/web2py/d287bf6d-df95-47b7-ba3b-4062bc12b772n%40googlegroups.com
> <https://groups.google.com/d/msgid/web2py/d287bf6d-df95-47b7-ba3b-4062bc12b772n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/web2py/CAC5t_Jy%3D1cb2cARHRV8wOdNbh04TL0W_aXnf6BY22-NxLdpwpg%40mail.gmail.com.

Reply via email to