No video

Sending Form Data (POST) with the Fetch API in JavaScript

  Рет қаралды 202,832

dcode

dcode

Күн бұрын

In this video we look at sending form data (POST) with the Fetch API. Fetch makes it super easy to do this and is great for making asynchronous, mobile friendly web applications.
The example involves logging in to a site asynchronously. Both types of data are covered: x-www-form-urlencoded and multipart/form-data.
Support me on Patreon:
/ dcode - with enough funding I plan to develop a website of some sort with a new developer experience!
For your reference, check this out:
developer.mozi...
Follow me on Twitter @dcode!
If this video helped you out and you'd like to see more, make sure to leave a like and subscribe to dcode!
#dcode #javascript #webdev

Пікірлер: 90
@webdev4786
@webdev4786 3 жыл бұрын
people like you are making the world a better place.
@dcode-software
@dcode-software Жыл бұрын
*RELATED VIDEO: UPLOAD FILES WITH THE FETCH API* kzfaq.info/get/bejne/mcuZZaaZm56XoWQ.html 🏷 *THE ULTIMATE JAVASCRIPT DOM CRASH COURSE* 👇 www.udemy.com/course/the-ultimate-javascript-dom-crash-course/?referralCode=DC343E5C8ED163F337E1
@1000hourshower
@1000hourshower Жыл бұрын
You helped me out big time. You're the only chap on here making sense with this matter. Thanks.
@karentutor5470
@karentutor5470 4 жыл бұрын
Thx for this I honestly spent a long time looking for a simple way to submit form data using the fetch api - this fits the bill. Thanks again for the great tutorial!
@akshitkhajuria4362
@akshitkhajuria4362 4 жыл бұрын
Great tut. But you should never send sensitive info like passwords as URL encoded strings. Use POST with https instead. POST method doesn't encode query params in the url.
@Levelord92
@Levelord92 5 жыл бұрын
Fucking awesome dude! I finally understand that FormData is an analog for jquery's serialize() form and pushing it into array, which we then send with data key.
@dcode-software
@dcode-software 5 жыл бұрын
Yeah that's it mate!!
@hoo_chuchu_0901
@hoo_chuchu_0901 4 жыл бұрын
고맙다!! 당신 덕분에 문제를 해결했다. 중요한내용을 확실히 집어주는 당신은 정말 최고! 나의 스승이 되어줘! Thank you !! You solved the problem. You are really nice guy! Be my teacher!
@Unerty
@Unerty 4 жыл бұрын
If you get an error "Failed to construct 'FormData': parameter 1 is not of type 'HTMLFormElement'", then replace const formData = new FormData(this); with const formData = new FormData(HERE_PUT_YOUR_FORM_OBJECT); For example, i if you have const myForm = document.getElementById("myForm"); then put const formData = new FormData(myForm);
@basselturky4027
@basselturky4027 2 жыл бұрын
Thank you legend
@Lord-v2s
@Lord-v2s 3 жыл бұрын
Please help me, I keep getting an *http 405 (Method not Allowed)* error when I run my project. What do I do? Do I have to change something in *Xampp*?
@holup5035
@holup5035 2 жыл бұрын
same
@davidmajdandzic7388
@davidmajdandzic7388 3 жыл бұрын
Thank you so much! Your video just ended hours of head scratching and screaming swear words! 🥳
@stepdate
@stepdate 4 жыл бұрын
Thank you, this was extremely helpful!
@bjornleonhenry9750
@bjornleonhenry9750 4 жыл бұрын
your videos are explosive 💥 coding dynamite
@inteltone
@inteltone 11 ай бұрын
Thanks a lot for this video tutorial! It is very useful.
@cjmarchi
@cjmarchi 5 жыл бұрын
simple and 100% working solution. Tks :)
@dcode-software
@dcode-software 5 жыл бұрын
No problem :)
@steveg917
@steveg917 4 жыл бұрын
not 100%.. the "this" go to the window.. you need to bind it
@coredatallc5671
@coredatallc5671 4 жыл бұрын
Very nice video. Now extend this to include MySQL query response using PDO and you will have a gem.
@sir.charless.7443
@sir.charless.7443 4 жыл бұрын
you didn't show the php file, how do use the the data sended?
@hitsu-kun
@hitsu-kun 3 жыл бұрын
Thanks so much! You save my day
@dcbiz
@dcbiz 3 жыл бұрын
Very helpful and much appreciated.
@tamas-pamas
@tamas-pamas 5 жыл бұрын
When would you use urlencoded form data and multipart form data? what is the point to parse into URLSearchParams object? To me it is just an extra step
@randomvideoguy3340
@randomvideoguy3340 4 жыл бұрын
I love you for posting this ty so much
@dcode-software
@dcode-software 4 жыл бұрын
No worries mate 😁
@pastorfred2543
@pastorfred2543 4 жыл бұрын
Wow..This is super useful.. Thanks
@arashnikbakht129
@arashnikbakht129 4 жыл бұрын
Great video, how can we send inputs like this one
@alexandreferreira5477
@alexandreferreira5477 3 жыл бұрын
Awesome! Thank you
@brunogigliofreitas
@brunogigliofreitas 3 жыл бұрын
The "this" didnt work for me
@holup5035
@holup5035 2 жыл бұрын
you probably used arrow function in addEventListener
@angladephil
@angladephil 4 жыл бұрын
Thank you very much for this and your other tutorials, which I follow with great attention and benefit ! Sorry I come late after this video, but I have a question : how to handle so simply the FormData object (and it's data) without PHP? For example through Node.js ? Thank you in advance . Greetings from France.
@guruprasadhmathivanan4040
@guruprasadhmathivanan4040 3 жыл бұрын
Hi sir I'm guruprasadh
@guruprasadhmathivanan4040
@guruprasadhmathivanan4040 3 жыл бұрын
From india
@guruprasadhmathivanan4040
@guruprasadhmathivanan4040 3 жыл бұрын
I've created an rest api using spring boot
@guruprasadhmathivanan4040
@guruprasadhmathivanan4040 3 жыл бұрын
But I give value using postman
@camera-support-rentals
@camera-support-rentals 4 жыл бұрын
Okay I got it to work and put the data into my database. How do I use the response to let the user know the post worked? I would like to do an if statement on the text variable but not sure how to do it? Thanks for the great easy to understand tutorial
@madsnielsen9295
@madsnielsen9295 4 жыл бұрын
Thank you very much for this tutorial. Can i ask what kind of parameter type would my restful API POST request need?
@muhammadzubair4754
@muhammadzubair4754 4 жыл бұрын
how to load html form data using json data file?
@nidhishettigar6981
@nidhishettigar6981 2 жыл бұрын
I am getting error - uncaught typeerror cannot read properties of null(reading addeventlisterner) . This is for variable myform. How can i solve this error please help!!!
@syrymzhakypbekov1949
@syrymzhakypbekov1949 4 жыл бұрын
very informative !
@kolinsukhadia3219
@kolinsukhadia3219 3 жыл бұрын
array(0){ } server show this so what I have to do to solve this error?
@IBITZEE
@IBITZEE 4 жыл бұрын
a teaser... strictly at client side (no control over the server...) I need to pass the form data from one page to the next called page... but with (yeah,,, with post) I know I can do it via GET/parms-in-url via H5/localStorage or via H5/sessionStorage... but??? is there anyway to do it with POST/action??? the form information/fields,,, of course are in the HTTP headers...
@jeremiahjohnson1594
@jeremiahjohnson1594 4 жыл бұрын
this is with php...what of js
@s.agamerz7962
@s.agamerz7962 3 жыл бұрын
What a typing speed
@dcode-software
@dcode-software 3 жыл бұрын
👀👀👀
@handersenadriano1309
@handersenadriano1309 5 жыл бұрын
thanks very much
@dcode-software
@dcode-software 5 жыл бұрын
No worries mate!
@troonder6274
@troonder6274 Жыл бұрын
NICE NICE NICE, thanks ^^
@ajmalnajath1399
@ajmalnajath1399 3 жыл бұрын
this is keybaord asmr
@shazythings8798
@shazythings8798 2 жыл бұрын
Helpful
@luismaestro23
@luismaestro23 3 жыл бұрын
what about the php file where you recieve the formdata
@dipzera1025
@dipzera1025 4 жыл бұрын
How would you combine this with validation?
@robitops1547
@robitops1547 4 жыл бұрын
Thanks but input:file return Object not value
@guruprasadhmathivanan4040
@guruprasadhmathivanan4040 3 жыл бұрын
How to send form data using fetch api with raw data
@bryandelacruz9066
@bryandelacruz9066 5 жыл бұрын
thanks do you also have a code for edit and delete? thanks
@kemmrthappy2804
@kemmrthappy2804 5 жыл бұрын
thanks a bit can u try out using fetch api with a input type=file
@naomifeedcow
@naomifeedcow 3 жыл бұрын
Awesome!
@vazhamikadze4018
@vazhamikadze4018 2 жыл бұрын
Thanks
@camera-support-rentals
@camera-support-rentals 4 жыл бұрын
I took out all of my arrow functions and it still does not show up in the PHP page. Is there something I have to do in the php page to see the data?
@dcode-software
@dcode-software 4 жыл бұрын
Which web server are you using?
@camera-support-rentals
@camera-support-rentals 4 жыл бұрын
@@dcode-software Hi Dom thanks for the help! XAMP MYSQL PHP ! the var_dump($_POST) on the php page is showing array(0) { } however I can see my response and I can see the message that I echoed from the php page in the console.log(). my javascript page is seperate from my html page I don't know if that makes a difference. Thanks for your help!
@camera-support-rentals
@camera-support-rentals 4 жыл бұрын
I need to put the data into my database
@undefined4851
@undefined4851 4 жыл бұрын
@@camera-support-rentals have you figured out solution? Getting same thing as you
@joe-powell
@joe-powell 2 жыл бұрын
@@dcode-software I have the same problem, is it a problem using localhost?
@WebdesignemFoco
@WebdesignemFoco 3 жыл бұрын
Wonderfull
@augischadiegils.5109
@augischadiegils.5109 2 жыл бұрын
❤️❤️❤️
@dopamine_Seeker
@dopamine_Seeker 3 жыл бұрын
not working I am furious in my local host $_post not working as I expected
@guruprasadhmathivanan4040
@guruprasadhmathivanan4040 3 жыл бұрын
In postman
@augischadiegils.5109
@augischadiegils.5109 2 жыл бұрын
❤️❤️
@Amigaudio
@Amigaudio 6 ай бұрын
Really? Your name is Dom?
@deepumon.d3148
@deepumon.d3148 4 жыл бұрын
You didn't showed data s in console.log()
@cat-typing2803
@cat-typing2803 4 жыл бұрын
Don't use arrow function in addEventListener
@tazulislam2698
@tazulislam2698 2 жыл бұрын
Bro, How to pass 2d array? [["",""],["",""]]
@allandiego1446
@allandiego1446 4 жыл бұрын
If I put in with the empty action is correct too?
@ulvidamirli2758
@ulvidamirli2758 4 жыл бұрын
Yes, e.preventDefault() ignores it.
@epickaowca8850
@epickaowca8850 5 жыл бұрын
canno't post /login.php POST 404 not found can some one help me ?
@dcode-software
@dcode-software 5 жыл бұрын
My wild guess it's to remove the / in front
@dcode-software
@dcode-software 5 жыл бұрын
If that helped you then check out my video on different kinds of links: kzfaq.info/get/bejne/nMCafsZj0LOviYk.html It should clear it up for you
@epickaowca8850
@epickaowca8850 5 жыл бұрын
that can't help because i write code like you in this video so i don't have ''/'' in front :(
@epickaowca8850
@epickaowca8850 5 жыл бұрын
i can fetch data from any file but i can't use post method because of 404 error
@dcode-software
@dcode-software 5 жыл бұрын
404 means not found so you just need to ensure login.php exists and if it does then ensure the path you've given is correct
@truonghoang7982
@truonghoang7982 3 жыл бұрын
Ok ok 👌
@MrPDTaylor
@MrPDTaylor 5 жыл бұрын
First
@josiahsprankle1146
@josiahsprankle1146 3 жыл бұрын
You moved very quickly, didn't explain much, and were hard to follow.
1.1: fetch() - Working With Data & APIs in JavaScript
15:39
The Coding Train
Рет қаралды 452 М.
Sending a form using the FormData object - JavaScript Tutorial
13:10
OpenJavaScript
Рет қаралды 38 М.
I Took a LUNCHBAR OFF A Poster 🤯 #shorts
00:17
Wian
Рет қаралды 8 МЛН
А ВЫ УМЕЕТЕ ПЛАВАТЬ?? #shorts
00:21
Паша Осадчий
Рет қаралды 2 МЛН
Just Give me my Money!
00:18
GL Show Russian
Рет қаралды 539 М.
If Barbie came to life! 💝
00:37
Meow-some! Reacts
Рет қаралды 78 МЛН
How to Use Local Storage in JavaScript
15:23
dcode
Рет қаралды 283 М.
The New dialog HTML Element Changes Modals Forever
12:09
Web Dev Simplified
Рет қаралды 585 М.
This is the Only Right Way to Write React clean-code - SOLID
18:23
1.4: JSON - Working with Data and APIs in JavaScript
16:22
The Coding Train
Рет қаралды 643 М.
Rest API - Best Practices - Design
15:50
High-Performance Programming
Рет қаралды 106 М.
Always Check for the Hidden API when Web Scraping
11:50
John Watson Rooney
Рет қаралды 621 М.
Save user form input data in a JavaScript object
7:10
OpenJavaScript
Рет қаралды 40 М.
How to FETCH data from an API using JavaScript ↩️
14:17
Bro Code
Рет қаралды 120 М.
I Took a LUNCHBAR OFF A Poster 🤯 #shorts
00:17
Wian
Рет қаралды 8 МЛН