JavaScript XHR - "responseType" Property vs "Content-Type" Header

Viewed 1581

A quick question arose to me while creating a simple, shareable XHR implementation for upcoming project.

What would the difference be in specifying the responseType property as json rather than the Content-Type header? Would everything be okay down the line if I did BOTH?

Thanks in advance for any insight! Thought this might start a good conversation.

1 Answers

The Content-type header is the format of parameters that the client is sending to the server in the POST data. This defaults to application/x-www-form-urlencoded, unless you send a FormData object, in which case it's multipart/form-data. If you send some other format (e.g. JSON) you should set the Content-type header appropriately.

responseType is the type of data that the server is sending to the client in its response.

Related