Ajax 是否通过网络同时发送 ResponseJson 和 ResponseText?

Does Ajax send both ResponseJson and ResponseText over the wire?

在我的 ajax 回复中,我有 responseJSONresponseText。我的问题只是,两者都是响应的一部分,还是 responseText 来自客户端的 responseJSON 或反之亦然?

因为在我的例子中它们是相同的,这意味着响应可能有两次相同的数据。似乎没有必要,而且可能会浪费数据传输。

没有足够的街头信誉来嵌入图像: screenshot of response

谢谢, 格雷格

这些只是您的 js 客户端为您提供的两种不同的表示形式。响应仅遵守 HTTP 标准,如 this example response message.

根据你的问题,responseJSON 只是 json 解析后的 responseText。

编辑:数据类型属性 文档:

If text or html is specified, no pre-processing occurs. The data is simply passed on to the success handler, and made available through the responseText property of the jqXHR object.

If json is specified, the response is parsed using jQuery.parseJSON before being passed, as an object, to the success handler. The parsed JSON object is made available through the responseJSON property of the jqXHR object.