The Internet Explorer browser does not correctly download the file

I have a problem downloading a file with Internet Explorer in any version. My problem is that I receive a bit array from my controller which I receive in a JSON and download it from javascript.

Note: I do not have a physical file on the server, this file is obtained from a storage by means of a WebService.

Code works fine in other browsers but not in Internet Explorer

$.ajax({
    type: 'POST',
    url: '/Portal/GetXML',
    data: $('#formDownload2' + id).serialize(),
    success: function (data) {
        if (data.error == "") {
            //aquí empieza la descarga del archivo
            var arr = data.Archivo;
            var byteArray = new Uint8Array(arr);
            var a = window.document.createElement('a');
            a.href = window.URL.createObjectURL(new Blob([byteArray], { type: 'application/octet-stream' }));
            a.download = data.Nombre;
            // Append anchor to body.
            document.body.appendChild(a)
            a.click();
            // Remove anchor from body
            document.body.removeChild(a)
        } else {
            $.jGrowl("" + data.error, {
                header: "Error",
                //sticky: true,
                theme: "red"
            });
        }
    }
});

All it does is download a file with a long name and no extension. On other computers with Internet Explorer Download a file with Extension: .JSON

¿Why is it that I download them like that? and how can I fix it?

 4
Author: Marc Lemien, 2016-09-21

1 answers

This is classic of Internet Explorer, it is because Said browser does not know what to do with content application/json

What we must specify is the content when returning JSON we define: string Content Type: "text/html"

In your controller that returns JSON:

return Json(loQueRetorna, "text/html");

I suggest the text/html you define as long as the browser IS IE.

 4
Author: fredyfx, 2016-09-21 00:46:06