Any idea for send POST for a function (url) via jquery-fancybox?

旧巷老猫 提交于 2019-12-12 03:13:44

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!