Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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

like image 262
shivamg11000 Avatar asked Oct 15 '17 04:10

shivamg11000


1 Answers

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.
like image 80
Aanand Kainth Avatar answered Nov 03 '22 15:11

Aanand Kainth