Jquery usage is declining over the last years, but still many javascript programmers are using it. I personally don't use Jquery, because i can do what i want with vanilla JavaScript. My opinion is to learn Javascript as best as you can, and then if you feel like to use a JS library, go for it.
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.
Hey, the error is in the PHP file and in the json_encode function. json_encode is a function so we use parentheses : json_encode($user); Happens to the best of us :)
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
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?
Instead of the username, my runtime console just logs the content of the PHP file. I assume the script is not even being executed. Is this related to the server configuration, or what could be the problem here?
You are correct, by displaying the PHP file's content the script is not executed. Check if your localhost server is running. Also i have the impression that if you use VS code with a live server it might not work. Hope it helps.
@@DigitalFox-tutorials Thank you, it was in fact a server configuration issue. I just got confused because I had the same problem both with my VS Code live server and my actual server.
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
@@DigitalFox-tutorials I don't get anything in the user variable, but in the js console everything comes in the usual form. What could be the problem and how to solve it?
Hey, maybe you have a typo in your code. Download the source code from my website and see if the problem exists. digitalfox-tutorials.com/tutorial.php?title=How-to-send-a-javascript-object-to-php
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?
best explanation for fetch with php and so short too! no time wasted.
Glad you liked it
OMG this is one of the best tutorial I've ever seen! Short, clear, everything is well explained...
Thank you so much!
+1 sub
Glad it helped!
Thank you for such an amazing video! Short and informative !
Thank you
Very nice and clear explanation. Just what I was looking for. Thanks for sharing! 👍
You're welcome!
THANKS I REALLY NEED THIS, other tutorials suggest use things like node or react but is really difficult for me to do, so THANKS
Thank you too. Glad it helped!
This was a great little snippet!
Thank you
short and clear explanation thank you very much sir.
Thanks and welcome
thank you so much sure, short and very helpful
Glad it helped
thanks a lot
do you recommend it to learn fetch without fully knowing about jquery?
You don't need to know jquery to use fetch. You use the Fetch API with plain JavaScript. JQuery is a JavaScript library.
@@DigitalFox-tutorials I'm just asking if jQuery still a good option to choose for use
Jquery usage is declining over the last years, but still many javascript programmers are using it. I personally don't use Jquery, because i can do what i want with vanilla JavaScript. My opinion is to learn Javascript as best as you can, and then if you feel like to use a JS library, go for it.
@@DigitalFox-tutorials aw cool thanks ❤️
Please a question: why do you use quotes on method, headers and body fields? In the official documentation they are not used. Thanks
You are right. Its a habit when i send an object to the server . But if i write an object that i will use later on in the script i don't use quotes.
Waooo 😜👍👍👍 no se hablar inglés, pero esto lo entiendo perfectamente, muchas gracias, necesitaba esto.
Thank you
Excellent explanation.
Glad you liked it
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)
You're welcome! Thank you.
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.
Hey, the error is in the PHP file and in the json_encode function. json_encode is a function so we use parentheses : json_encode($user);
Happens to the best of us :)
@@DigitalFox-tutorials Of course, thanks very much for your quick response to my oversight!
Why does my php echo an empty string?
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
Hey, check out this video, maybe it helps.
ua-cam.com/video/cbwLMSNkul0/v-deo.html
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?
Sorry i am not familiar with the liquid templating language. I hope you find the answer to your problem.
Instead of the username, my runtime console just logs the content of the PHP file. I assume the script is not even being executed. Is this related to the server configuration, or what could be the problem here?
You are correct, by displaying the PHP file's content the script is not executed.
Check if your localhost server is running.
Also i have the impression that if you use VS code with a live server it might not work.
Hope it helps.
@@DigitalFox-tutorials Thank you, it was in fact a server configuration issue. I just got confused because I had the same problem both with my VS Code live server and my actual server.
my requests keep getting blocked by CORS policy, why is that?
thnak you
thx a lot!
Welcome!
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
You can access the email and username using brackets like this :
echo $user["username"];
echo $user["email"];
@@DigitalFox-tutorials I don't get anything in the user variable, but in the js console everything comes in the usual form. What could be the problem and how to solve it?
Good
Thanks
thank you
You're welcome
Fetch script.php not found error how to deal with it
Hey, check your spelling, or download the source code from here:
digitalfox-tutorials.com/tutorial.php?title=How-to-send-a-javascript-object-to-php
Getting an error:- "Syntax Error: not a valid json"
It seems that you have a typo in you JSON file.
idk why but mine doesn't work.
:(
Hey, maybe you have a typo in your code.
Download the source code from my website and see if the problem exists.
digitalfox-tutorials.com/tutorial.php?title=How-to-send-a-javascript-object-to-php
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?