How to send a javascript object to a php file using the fetch method |

preview_player
Показать описание
We are going to send a javascript object with a post
request to a php file using the fetch method.

Also we are going to see how to catch the php response
in the javascript file.

There will be a back and forth transaction, from the
javascript file to the php file.

You can also read the article on my website:

My facebook page:

If you feel like saying thanks, you can buy me a coffee.
Рекомендации по теме
Комментарии
Автор

best explanation for fetch with php and so short too! no time wasted.

Chieko-ed
Автор

OMG this is one of the best tutorial I've ever seen! Short, clear, everything is well explained...
Thank you so much!
+1 sub

ncciac
Автор

Very nice and clear explanation. Just what I was looking for. Thanks for sharing! 👍

troymelok
Автор

Thank you for such an amazing video! Short and informative !

AnnabelleSwan
Автор

THANKS I REALLY NEED THIS, other tutorials suggest use things like node or react but is really difficult for me to do, so THANKS

lilarkzuli
Автор

short and clear explanation thank you very much sir.

sam-jzy
Автор

Waooo 😜👍👍👍 no se hablar inglés, pero esto lo entiendo perfectamente, muchas gracias, necesitaba esto.

digitalstablerds
Автор

thank you so much sure, short and very helpful

nouhafougi
Автор

Instead of the username, my runtime console just logs the content of the PHP file. I assume the PHP script is not even being executed. Is this related to the server configuration, or what could be the problem here?

Bengt-xwyj
Автор

Thank you so much for your video🫡 I was struggling with my code for over two hours, but then I found your video. You're amazing mate)

troonder
Автор

Please a question: why do you use quotes on method, headers and body fields? In the official documentation they are not used. Thanks

troymelok
Автор

my requests keep getting blocked by CORS policy, why is that?

abdurahmanaqlan
Автор

thanks a lot
do you recommend it to learn fetch without fully knowing about jquery?

reving
Автор

This worked for me when using text in the script.js file and echo $user["username"] but when I changed to return response.json(); and echo json_encode[$user]; I get Undefined constant json_encode error. For let user I have an unexpected parsing error user.

michaelmcgrath
Автор

I have successfully did that, now I want to use this object user to store its values in the database. I am not been able to echo or print_r values. How ever i can clearly see array/object in console

anarishakari
Автор

I have a js file with liquid syntax and my linter is giving me errors, I read online that it might be best to split the file so that the liquid deals with the data and js handle the logic. but it doesn't seem to work for me.. I feel like it's not in sync and they mentioned using fetch, will this concept work with js and liquid syntax as well you think?

ronaldpaek
Автор

why it is echoing Null in the php file?I want to echo the username and email in the php file .How can i do that?Please write the code to explain.It'll be very helpful

anindabarua
Автор

Getting an error:- "Syntax Error: not a valid json"

indrajitmandal
Автор

idk why but mine doesn't work.
:(

lovikim
Автор

Fetch script.php not found error how to deal with it

amit_fran_dev