The Internet Explorer browser does not download the file correctly

4

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

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

The code works well 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"
            });
        }
    }
});

The only thing 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 should I download them in that way? and How can I solve it?

    
asked by JuankGlezz 21.09.2016 в 02:15
source

1 answer

4

This is classic of Internet Explorer , it is because that 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"

On your controller that returns JSON :

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

I suggest the text/html define it as long as the browser is IE.

    
answered by 21.09.2016 / 02:21
source