I came across blob
while searching some stuff in jQuery. Googled about it but could not exactly figure out what kind of concept it is.
I found this code for downloading a pdf file through Ajax.
$.ajax({
method: 'GET',
dataType: 'blob',
data: { report_type: report_type, start_date: start_date, end_date: end_date, date_type: date_type },
url: '/reports/generate_pdf.pdf',
success: function(data) {
var blob=new Blob([data]);
var link=document.createElement('a');
link.href=window.URL.createObjectURL(blob);
link.download="Report_"+new Date()+".pdf";
link.click();
console.log("pdf printed");
}
});
This code is working fine but printing empty pdf without the content either static or dynamic. But with a strange behaviour. I.e. if the dynamic data calculated is too big, it is generating multiple pages.
I just want to figure out the concept of blob
so that I can figure out myself what this piece of code is doing and how does blob
work.
Any proper guide or help would be really appreciated. Thanks in advance!
jQuery.ajax()
does not returnBlob
response by default.XMLHttpRequest()
withresponseType
set toBlob
?