GET and POST are the two commonly used HTTP methods. The REST API calls can return a variety of response data types like text, array buffer, blob, document, and JSON. Let us discuss the lesser-known response datatypes in this article.
var xml = new XMLHttpRequest();
The above piece of code helps you with the request, the response would look as below
xml.responseType = 'blob';
There are 5 data types that a responseType can accommodate, they are
- array buffer
Document: Results are assumed to an XML document. It could be an HTML document as well. The server is responsible for validating and sending the HTML to the client.
Text: Response contains a string of text.
JSON: Response contains a JSON document. This is a very popular format in the REST calls.
ArrayBuffer: Response contains an array of binary data. The developer cannot manipulate or display the array buffer contents directly. Instead, the developer needs to use a typed array view that can process the array buffer. As the name suggests, they are used in streaming audio/video to the frontend.
Blob: Response contains a file-like object of raw data.
The loader animation can be changed on certain ajax events like
abort - triggered when the user cancels the download in this case
var request = new XMLHttpRequest();