Возвращает с ошибкой. Не знаю как побороть.
success: function(response, status, xhr)
{
// check for a filename
var filename = "";
var disposition = xhr.getResponseHeader('Content-Disposition');
if (disposition && disposition.indexOf('attachment') !== -1) {
var filenameRegex = /filename[^;=\n]*=((['"]).*?\2|[^;\n]*)/;
var matches = filenameRegex.exec(disposition);
if (matches != null && matches[1]) filename = matches[1].replace(/['"]/g, '');
}
var typecontent = xhr.getResponseHeader('Content-Type');
var blob = new Blob([response], { type: typecontent, endings: 'transparent'});
if (typeof window.navigator.msSaveBlob !== 'undefined') {
// IE workaround for "HTML7007: One or more blob URLs were revoked by closing the blob for which they were created. These URLs will no longer resolve as the data backing the URL has been freed."
window.navigator.msSaveBlob(blob, filename);
} else {
var URL = window.URL || window.webkitURL;
var downloadUrl = URL.createObjectURL(blob);
if (filename) {
// use HTML5 a[download] attribute to specify filename
var a = document.createElement("a");
// safari doesn't support this yet
if (typeof a.download === 'undefined') {
window.location = downloadUrl;
} else {
a.href = downloadUrl;
a.download = filename;
document.body.appendChild(a);
a.click();
}
} else {
window.location = downloadUrl;
}
setTimeout(function () { URL.revokeObjectURL(downloadUrl); }, 100); // cleanup
}
document.body.style.cursor = 'default';
gantt.ajax_screen = false;
console.log("success");
},
В случае успеха, необходимо вернуть картинку Серверная сторона:
$path = JPATH_ROOT.'/tmp';
ob_end_clean();
header('Content-Description: File Transfer');
header("Content-Type: application/octet-stream");
header("Content-Length: " . filesize($path . '/' . $hash.'.png'));
header("Content-Disposition: attachment; filename=\"" . $hash.".png" . "\";");
header("Content-Transfer-Encoding: Binary");
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
if (function_exists('readfile')) {
readfile($path . '/' . $hash.'.png');
}
else {
echo file_get_contents($path . '/' . $hash.'.png');
}
jexit();
А результат:
Может кто добрым советом поможет? Буду очень благодарен!