$.ajax({
type: "POST",
url: "../report.php",
dataType: "json",
cache: false,
contentType: false,
processData: false,
data: formData,
success: function(data, respond, textStatus, jqXHR){
console.log(respond);
},
error: function(jqXHR, textStatus, errorThrown) {
console.log('Ошибка: ' + textStatus + ' | ' + errorThrown);
}
<?php
/* Здесь проверяется существование переменных */
if (isset($_POST['a'])) {$a = $_POST['a'];}
if (isset($_POST['b'])) {$b= $_POST['b'];}
..........
/**
Здесь идут всякие расчеты и переменные
**/
......
echo json_encode($arResult);
require_once( "fpdf/fpdf.php" );
/**
Создаем страницу
**/
$pdf = new FPDF( 'P', 'mm', 'A4' );
$pdf->AddFont('Calibri','','calibri.php');
$pdf->AddFont('Calibri-Bold','','calibrib.php');
$pdf->AddFont('Calibri-Italic','','calibrii.php');
$pdf->SetTextColor( $textColour[0], $textColour[1], $textColour[2] );
$pdf->AddPage();
.........
/**
Создаем форму с Расчетными данными
**/
.........
/***
Выводим PDF
***/
$pdf->Output( "report.pdf", "I" );
?>
$.ajax({
...
success: function(data) {
var file=document.createElement('a');
file.href=window.URL.createObjectURL(new Blob([data],{type: "application/pdf"}));
file.download="Report.pdf";
file.click();
}
});
$.ajax({
...
success: function(data) {
chrome.downloads.download({
url : URL.createObjectURL(new Blob([data],{type: "application/pdf"})),
filename : "Report.pdf",
conflictAction : 'uniquify'
});
}
});
(function($, undefined) {
"use strict";
// use this transport for "binary" data type
$.ajaxTransport("+binary", function(options, originalOptions, jqXHR) {
// check for conditions and support for blob / arraybuffer response type
if (window.FormData && ((options.dataType && (options.dataType == 'binary')) || (options.data && ((window.ArrayBuffer && options.data instanceof ArrayBuffer) || (window.Blob && options.data instanceof Blob))))) {
return {
// create new XMLHttpRequest
send: function(headers, callback) {
// setup all variables
var xhr = new XMLHttpRequest(),
url = options.url,
type = options.type,
async = options.async || true,
// blob or arraybuffer. Default is blob
dataType = options.responseType || "blob",
data = options.data || null,
username = options.username || null,
password = options.password || null;
xhr.addEventListener('load', function() {
var data = {};
data[options.dataType] = xhr.response;
// make callback and send data
callback(xhr.status, xhr.statusText, data, xhr.getAllResponseHeaders());
});
xhr.addEventListener('error', function() {
var data = {};
data[options.dataType] = xhr.response;
// make callback and send data
callback(xhr.status, xhr.statusText, data, xhr.getAllResponseHeaders());
});
xhr.open(type, url, async, username, password);
// setup custom headers
for (var i in headers) {
xhr.setRequestHeader(i, headers[i]);
}
xhr.responseType = dataType;
xhr.send(data);
},
abort: function() {}
};
}
});
})(window.jQuery);
$.ajax({
type: "POST",
url: "../report.php",
data: formData,
dataType: 'binary',
processData: false,
success: function (resp, status, xhr) {
var disposition = xhr.getResponseHeader('Content-Disposition');
var filename = disposition.substring(disposition.indexOf('filename=') + 'filename='.length).replace(/['"]/g, '');
var type = xhr.getResponseHeader('Content-Type');
var blob = new Blob([resp], {type: type});
var download_url = (window.URL || window.webkitURL).createObjectURL(blob);
var a = document.createElement("a");
a.href = download_url;
a.download = filename;
document.body.appendChild(a);
a.click();
},
error: function (xhr) {
...
}
});
<a class="rez" style="display:none" download="" href="" target="_blank"></a>
jQuery.ajax({
type: "POST",
url: "report.php",
data: arr,
success: function(data){
var result = jQuery.parseJSON( data );
jQuery('.rez').attr('href', result.doc);
jQuery('.rez')[0].click();
}
});
$uniqid = uniqid();
$pdf = new PDF();
........
$path = "pdf/".$uniqid.".pdf";
$pdf->Output($path,'F');
$doc = 'pdf/'.$uniqid.'.pdf';
echo json_encode(array('doc' => $doc ));