简体   繁体   English

XMLHTTPRequest responseBody vs responseText

[英]XMLHTTPRequest responseBody vs responseText

I've always referenced the body property on an XMLHTTPRequest response because it's always a nice usable parsed js object. 我总是在XMLHTTPRequest响应上引用body属性,因为它始终是一个很好的可用解析js对象。 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. 但是这次主体是空的,响应就是在.text中进行字符串化,我想知道为什么会这样,以及在服务器/客户端交互中使用一个而不是另一个的权衡。

Your server is responding with the wrong Content-Type header. 您的服务器使用错误的Content-Type标头进行响应。 Ensure it is set to something reasonable like application/json . 确保它设置为像application/json那样合理的东西。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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