简体   繁体   中英

JavaScript XHR - “responseType” Property vs “Content-Type” Header

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.

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 (eg 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM