I am currently learning about web development and came across HTTP. One thing that is confusing me is how exactly to make HTTP requests. In the videos I've watched the main way they send HTTP requests are through Form Elements. Doing a little bit more research, I also found out that HTTP requests can be done manually via Fetch and XMLHttpRequest.
So I'm a bit confused on how all 3 of these work and the benefits of choosing one over the other. I do apologize if I make any mistakes, but I'm largely confused on the entire matter. I tried manually sending HTTP Requests like PUT and POST with Fetch, but that was kind of a mess. Most tutorials were using Form Elements to do so, so now I'm left wondering if that's just how it should be done.
I also read over Sending forms through JavaScript but it completely went over my head.
So I tried looking up various tutorials and websites to explain the matter of HTTP requests with HTML/CSS & Javascript. I'm hoping that someone can explain the differences between Forms, Fetch, and XMLHttpRequest. And what are the tradeoffs of using one over the other if that is applicable in this case.
I'm no expert on this topic but there are different use cases for Form
, fetch
and XMLHttpRequest
fetch
is preferred to XMLHttpRequest
because it is newer and allows a more modern interface to perform requests. In comparison to forms, you can choose the body/request content through JavaScript.TLDR; Use fetch
if you want a modern api, use XMLHttpRequest
if you need an older api, and use a form element if you want to send data from a series of html elements
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With