View Single Post
Old 27-05-2020, 14:53   #5
robertino_salemi
Senior Member
 
L'Avatar di robertino_salemi
 
Iscritto dal: Apr 2009
Cittā: Aci Catena (CT)
Messaggi: 922
Esatto, lo StatusCode č diverso e non mi spiego come mai.

Certo, ecco la chiamata Ajax:
Codice:
    $.ajax({
        type: "POST",
        url: url_with_params,
        headers: {
            'Authorization': 'Bearer ' + sessionStorage.getItem(JWTTokenName),
            'Content-Type': "application/json;charset=UTF-8"
        },
        // Seems like the only way to get access to the xhr object
        xhr: function () {
            var xhr = new XMLHttpRequest();
            xhr.responseType = 'blob'
            return xhr;
        },
        data: jsonData,
        cache: true,
        success: function (data, status, xhr) {
            var blob = new Blob([data], { type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet" });

            var downloadUrl = URL.createObjectURL(blob);

            //Get fileName
            var headers = xhr.getAllResponseHeaders();
            var arr = headers.trim().split(/[\r\n]+/);
            // Create a map of header names to values
            var headerMap = {};
            arr.forEach(function (line) {
                var parts = line.split(': ');
                var header = parts.shift();
                var value = parts.join(': ');
                headerMap[header] = value;
            });
            var fileName = headerMap["content-disposition"];

            var a = document.createElement("a");
            a.href = downloadUrl;
            a.download = fileName;
            document.body.appendChild(a);
            a.click();
            document.body.removeChild(a);
        },
        error: function (err, type, httpStatus) {
            var failureMessage = 'Error occurred in ajax call ' + err.status + " - " + err.responseText + " - " + httpStatus;
			console.log(failureMessage);
        }
    });
__________________
robertino_salemi č offline   Rispondi citando il messaggio o parte di esso