XMLHttpRequest上的xhr.response和xhr.responseText之间的区别? [英] Difference between xhr.response and xhr.responseText on XMLHttpRequest?

查看:230
本文介绍了XMLHttpRequest上的xhr.response和xhr.responseText之间的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在执行"GET"请求时, xhr.response xhr.responseText 都返回相同的值.有什么不同?有吗?

When doing a 'GET' request, xhr.response and xhr.responseText both return the same value. What's the difference? Is there any?

推荐答案

响应被解释为 ArrayBuffer Blob Document ,JavaScript对象或 DOMString ,具体取决于 XMLHttpRequest.responseType 的值.另一方面, responseText 是原始文本,您可以根据需要进行处理.它们的用法非常相似.

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.

  1. 从服务器获取JSON并将其转换为JavaScript对象时,您可以使用 response .
  2. 当您不拥有服务器时,可以使用 responseText ,而 responseType 是您不想使用的格式.
  1. You can use response when you get JSON from the server, and have it translated into a JavaScript object.
  2. You can use responseText when you don't own the server, and the responseType is a format you don't want to use.

这篇关于XMLHttpRequest上的xhr.response和xhr.responseText之间的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆