Using XMLHTTPRequest (ajax) transporting data between client and server has been popular for a while. Sometimes, we want our browser to retrieve binary data from server (as ArrayBuffer or Blob) such as pdf, image, and psd files. This post will go through how to achieve it with XMLHTTPRequest and jQuery.
For XMLHTTPRequest, just simply setup the responseType of XHR instance to either arraybuffer or blob. Example:
\$.ajax does not support either arraybuffer or blob as its dataType. Thus we need write a beforeSend handler:
For more information about responseType, take a look at this.