问题
I need to display a PDF report generated from a PHP function in a jquery-fancybox.
The problem is that I need to submit $_POST
form data to the fancybox. Could you give me an idea of how to do this?
jQuery function that performs the function to generate the report:
$(function() {
$("*").on("click", ".fancypdf", function() {
var form = $("form").serialize();
var url = this.value;
console.log("Button=" + url);
$.fancybox({
type: 'html',
autoSize: false,
content: '<embed src="' + url + '#nameddest=self&page=1&view=FitH,0&zoom=80,0,0" type="application/pdf" height="99%" width="100%" />',
beforeClose: function() {
$(".fancybox-inner").unwrap();
}
}); //fancybox
return false;
}); //click
});
PHP function that generates the report PDF:
function exibirRelatorioPDF($dados = '') {
echo "POST=<br />";
print_r($_POST);
$dados = $this->pesquisar();
echo "Pesquisado";
CarregaJanelaPDF('almembal/ajuste', $dados);
}
回答1:
I'm solved the problem! I inserted a ajax request after opening fancybox.
$(function() {
$("*").on("click", ".fancypdf", function() {
var data = $("form").serialize();
var url = this.value;
console.log("Button=" + url);
console.log("Data=" + data);
$.fancybox({
type: 'ajax',
autoSize: false,
content: '<embed src="' + url + '#nameddest=self&page=1&view=FitH,0&zoom=80,0,0" type="application/pdf" height="99%" width="100%" />',
beforeClose: function() {
$(".fancybox-inner").unwrap();
}
}); //fancybox
$.ajax({
type: "POST",
cache: false,
url: url,
data: data,
success: function(data) {
$.fancybox(data);
}
});
return false;
}); //click
});
来源:https://stackoverflow.com/questions/17858472/any-idea-for-send-post-for-a-function-url-via-jquery-fancybox