1

Working with IE-10/11

I am downloading a file in JQuery

Common.ajax({
    dataType: 'text',
    type: 'GET',
    url: link,
    data: {'_CONV_ID': convId},
    success: function (data) {
        alert("File DOwnloaded" + data);
       //How to say Browser to open dialog to open, save cancel the file download
    },
    error: function (result) {
        $.unblockUI();
        $.log(result.responseText);
    }
});

Alert message successfully getting displayed on screen but dialog to save or open file does not appear. Anyone suggest what to write in success to get that?

fatherazrael
  • 5,511
  • 16
  • 71
  • 155

2 Answers2

1

try this..

var a = document.createElement('a');
var fileurl=  window.URL.createObjectURL(new Blob([byteArray], { type: 'application/octet-stream' }));
a.href =  fileurl;
a.download = filename; // Set the file name.
a.style.display = 'none';
document.body.appendChild(a);
a.click();
delete a;
window.URL.revokeObjectURL(fileurl);

byteArray should be from your data

sangram parmar
  • 8,462
  • 2
  • 23
  • 47
0

Bluish is completely right about this, you can't do it through Ajax because JavaScript cannot save files directly to a user's computer (out of security concerns). Unfortunately pointing the main window's URL at your file download means you have little control over what the user experience is when a file download occurs.

I created jQuery File Download which allows for an "Ajax like" experience with file downloads complete with OnSuccess and OnFailure callbacks to provide for a better user experience. Take a look at my blog post on the common problem that the plugin solves and some ways to use it and also a demo of jQuery File Download in action. Here is the source

Here is a simple use case demo using the plugin source with promises. The demo page includes many other, 'better UX' examples as well.

$.fileDownload('some/file.pdf')
    .done(function () { alert('File download a success!'); })
    .fail(function () { alert('File download failed!'); });
Community
  • 1
  • 1
Khodor Khalil
  • 49
  • 1
  • 5