Why did we pass an argument to xhr.send() for a POST request but not for GET?

Question

In the context of this exercise, why did we pass an argument to xhr.send() for a POST request, but not for a GET request?

Answer

If we recall the introduction text, a GET request is used to retrieve information from a source, while for a POST request, we “post” information to a source that processes the information and sends it back.

As a result, because a GET request is just for retrieving, we do not provide any argument to the xhr.send() method. However, for the POST request, we want to “post” the information, which is the JSON object in this exercise, by sending it through the xhr.send() method.

11 Likes

with that been said, we can omit the “xhr.send();” ?

1 Like

No. The xhr object must still submit the request to the web server. All the code up to this point is in preparation for this step.