I have some code in an Angular app that makes a GET request to a URL and saves the response data in a blob object. I've been asked to write similar functionality with jQuery.
After reviewing several posts on Stackoverflow, I wrote the following code:
jQuery.ajax({
url: url,
xhrFields: { responseType: "blob" },
cache: false,
xhr: function() {
var xhr = new XMLHttpRequest();
xhr.responseType = "blob";
return xhr;
},
success: function(data) {
// data contains the string "[Object blob]" instead of a blob representing the response
};
});
I've carefully reviewed my code and compared it to the examples, and I can't understand why, but the data passed back to my success handler is the string "[Object blob]" instead of the actual object. It looks like somehow, a blob was generated from the result of the HTTP request, but it got converted to a string 13 characters long.
I've checked everything I can find, but I haven't been able to produce a blob in my development environment. What am I doing wrong?
I am using jQuery 3.3.1