I've always referenced the body property on an XMLHTTPRequest response because it's always a nice usable parsed js object. But this time body is null and the response is sitting there stringified in .text and I'd like to know why that might be, and the tradeoffs to using one over the other in server / client interactions.
responseText. The read-only XMLHttpRequest property responseText returns the text received from a server following a request being sent.
The response is interpreted into a ArrayBuffer , Blob , Document , JavaScript object, or a DOMString , depending on the value of XMLHttpRequest. responseType . responseText , on the other hand is the raw text, and you can handle it however you want. They are very similar in usage though.
The XMLHttpRequest response property returns the response's body content as an ArrayBuffer , a Blob , a Document , a JavaScript Object , or a string, depending on the value of the request's responseType property.
Your server is responding with the wrong Content-Type
header. Ensure it is set to something reasonable like application/json
.
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