I'm trying to download a generated file(pdf) using Ajax, it's working perfectly in Chrome and IE but not in FireFox. Here is my code :
function Download(urlAction, urlDownload) {
$.ajax({
type: "post",
url: urlAction,
data: {
'itemIds': checkedItems,
'dateMin': datemin.toISOString(),
'dateMax': datemax.toISOString()
},
datatype: "json",
traditional: true,
success: function (data) {
console.log('fff', data);
if (data.success) {
window.location = urlDownload;
}
}
error: function (xhr, textStatus, err) {
console.log("readyState: " + xhr.readyState);
console.log("responseText: " + xhr.responseText);
console.log("status: " + xhr.status);
console.log("text status: " + textStatus);
console.log("error: " + err);
}
});
}
}
In the UrlAction I generate the file in Json format and post it in a session, then calling it again in my urlDownload. In Chrome and IE the file is downloaded without reloading the page, but in Firefox, it only reload the page.
The error says:
- readyState: 0
- responseText: undefined
- status: 0
- text status: error
- error: undefined