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

Поділитися
Вставка
  • Опубліковано 4 гру 2024

КОМЕНТАРІ • 61

  • @Chieko-e3d
    @Chieko-e3d 8 місяців тому +3

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

  • @ncciac
    @ncciac 8 місяців тому +2

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

  • @AnnabelleSwan
    @AnnabelleSwan Рік тому +2

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

  • @troymelok831
    @troymelok831 Рік тому +3

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

  • @lilarkzuli2948
    @lilarkzuli2948 4 місяці тому

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

  • @atouchofa.d.d.5852
    @atouchofa.d.d.5852 Рік тому

    This was a great little snippet!

  • @sam-j4zy
    @sam-j4zy Рік тому

    short and clear explanation thank you very much sir.

  • @nouhafougi1877
    @nouhafougi1877 10 місяців тому

    thank you so much sure, short and very helpful

  • @reving4896
    @reving4896 Рік тому +1

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

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  Рік тому

      You don't need to know jquery to use fetch. You use the Fetch API with plain JavaScript. JQuery is a JavaScript library.

    • @reving4896
      @reving4896 Рік тому +1

      @@DigitalFox-tutorials I'm just asking if jQuery still a good option to choose for use

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  Рік тому

      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.

    • @reving4896
      @reving4896 Рік тому +1

      @@DigitalFox-tutorials aw cool thanks ❤️

  • @troymelok831
    @troymelok831 Рік тому +1

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

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  Рік тому +1

      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.

  • @digitalstablerds2498
    @digitalstablerds2498 Рік тому

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

  • @amerbogilovic4808
    @amerbogilovic4808 Рік тому

    Excellent explanation.

  • @troonder6274
    @troonder6274 11 місяців тому

    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)

  • @michaelmcgrath5787
    @michaelmcgrath5787 7 місяців тому +1

    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.

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  7 місяців тому

      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 :)

    • @michaelmcgrath5787
      @michaelmcgrath5787 7 місяців тому

      @@DigitalFox-tutorials Of course, thanks very much for your quick response to my oversight!

  • @nicko9958
    @nicko9958 Рік тому +2

    Why does my php echo an empty string?

  • @anarishakari8627
    @anarishakari8627 Рік тому +1

    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

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  Рік тому

      Hey, check out this video, maybe it helps.
      ua-cam.com/video/cbwLMSNkul0/v-deo.html

  • @ronaldpaek
    @ronaldpaek Рік тому

    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?

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  Рік тому

      Sorry i am not familiar with the liquid templating language. I hope you find the answer to your problem.

  • @Bengt-xw9yj
    @Bengt-xw9yj 6 місяців тому

    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?

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  6 місяців тому

      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.

    • @Bengt-xw9yj
      @Bengt-xw9yj 6 місяців тому

      @@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.

  • @abdurahmanaqlan9634
    @abdurahmanaqlan9634 4 місяці тому

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

  • @charithnaiya
    @charithnaiya 3 місяці тому

    thnak you

  • @psychedelic-chi
    @psychedelic-chi Рік тому

    thx a lot!

  • @anindabarua6233
    @anindabarua6233 7 місяців тому

    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
      @DigitalFox-tutorials  7 місяців тому +1

      You can access the email and username using brackets like this :
      echo $user["username"];
      echo $user["email"];

    • @Lunar66
      @Lunar66 7 місяців тому

      @@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?

  • @Idiomeme_com
    @Idiomeme_com 10 місяців тому

    Good

  • @loljaar2002
    @loljaar2002 Рік тому

    thank you

  • @amit_fran_dev
    @amit_fran_dev Рік тому

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

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  Рік тому

      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

  • @indrajitmandal5985
    @indrajitmandal5985 8 місяців тому

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

  • @lovikim1637
    @lovikim1637 Рік тому

    idk why but mine doesn't work.
    :(

    • @DigitalFox-tutorials
      @DigitalFox-tutorials  Рік тому

      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

  • @Bengt-xw9yj
    @Bengt-xw9yj 6 місяців тому

    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?