I'm attempting to return an Excel file through a Ajax POST
to the server, the server generates the .xls file, however it doesn't pass through to the front end, i think it has something to do with how i'm handling the response.
It should kick off a file download of the Excel file. Originally i had dataType JSON
, but after searching through threads i figure it's something to do with the dataType
format and the .done
function, but cannot work out what it should be.
function requestFile(myJSON) {
var urlrequest = "mywebappexport/excel";
var link = $('#exportbtn');
$.ajax({
url: link.attr('href'),
type: "POST",
data: JSON.stringify(myJSON),
cache: true,
contentType: "application/json; charset=utf-8",
complete: function (data) {
var ifr = ($('<iframe />').attr('src', link.attr('href')).hide().appendTo(link))
setTimeout(function () {ifr.remove();}, 5000);
}
})
};
Updated code: working on modern browsers but fails on IE8 - with the error
Unexpected call to method or property access.
In jQuery version 1.9.1.js.
this.appendChild( elem );