0

i call this $.ajax method :

$.ajax({
    type: 'POST',
    data: JSON.stringify(data),
    contentType: 'application/json',
    url: 'http://46.101.209.16/endpoint',
    success : function(etichettas) {
        console.log(etichettas);

        var blob = new Blob([etichettas], {type: "application/pdf"});
        saveAs(blob, "Label.pdf");
    }//SUCCESS
});

and the "etichettas" is a pdf. the problem is that some chars : ���� how can i set the ajax call to see the original chars and don't chane it in � ? sorry for bad english, i'm tialian (:

Alessandro Zago
  • 793
  • 3
  • 12
  • 33
  • Are the weird characters in the pdf file? How is it created? Is it a static file or is it generated for each request? – JSchirrmacher May 09 '16 at 14:08
  • 1
    Ajax typically assumes UTF-8 encoded text, which a PDF file won't be (at least, not entirely). Once it tries to "decode" the file as text, any occurrence of � is lost data that can't be recovered. You can use the `XMLHttpRequest`'s `responseType` and `response` to receive the file as a `Blob` rather than text, though [you may not be able to use `jQuery.ajax()` for it](http://stackoverflow.com/questions/17657184/using-jquerys-ajax-method-to-retrieve-images-as-a-blob). – Jonathan Lonowski May 09 '16 at 14:10

0 Answers0