I have a problem downloading a file with Internet Explorer
any version. My problem is that I receive an array of bits from my controller which I receive in a JSON
and download 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 fine in other browsers but not inInternet 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 that way? and how can I solve it?
This is classic of
Internet Explorer
, it is because said browser does not know what to do with contentapplication/json
What we must specify is the content when we return
JSON
we define:string Content Type: "text/html"
In your controller that returns
JSON
:I suggest
text/html
you define it as long as the browser is IE.