Difference between xhr.response and xhr.responseText on XMLHttpRequest?

后端 未结 1 1008
太阳男子
太阳男子 2021-02-07 05:48

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

相关标签:
1条回答
  • 2021-02-07 06:29

    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. 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.
    0 讨论(0)
提交回复
热议问题