简体   繁体   English

如何在使用codeigniter调用ajax后在dompdf上呈现内容?

[英]How to render content on dompdf after ajax call using codeigniter?

<script>
    $(document).on("click",".pdf_sheet", function(){
        var subjectID = $("#subjectID").val();
        var session = $("#SessionFrom").val()+"-"+$("#SessionTo").val();
        var courseID = $("#classesID").val();
        var yearsOrSemester = $("#yearSemesterID").val();
        $.ajax({
            type: 'POST',
            url: "<?=base_url('student/sheetPDF')?>",
            data: {"subjectID":subjectID,"session":session,"courseID":courseID,"yearsOrSemester":yearsOrSemester},
            cache: false,
            success: function(data) {
            }
        });
    });
</script>

Controller:控制器:

function sheetPDF()
{
    $subjectID = $this->input->post('subjectID');
    $session = $this->input->post('session');
    $courseID = $this->input->post('courseID');
    $yearsOrSemester = $this->input->post('yearsOrSemester'); 
    $data['subjectID'] = $subjectID;
    $data['session'] = $session;
    $data['courseID'] = $courseID;
    $data['yearsOrSemester'] = $yearsOrSemester;
    $data['award'] = $this->classes->award($subjectID,$session,$courseID,$yearsOrSemester);
    $this->load->view('sheet',$data);
    $html = $this->output->get_output();
    $this->load->library('pdf');
    $this->dompdf->loadHtml($html);
    $this->dompdf->render();
    $this->dompdf->stream("Awardsheet.pdf", array("Attachment"=>1));
}

I am using DOMPdf to convert html to pdf file.我正在使用 DOMPdf 将 html 转换为 pdf 文件。 Now, What is happening when I click on pdf_sheet class then content are showing but not rendering on html.现在,当我点击pdf_sheet类然后内容显示但不呈现在 html 上时发生了什么。 So, How can I show view file on pdf file?那么,如何在 pdf 文件上显示视图文件? So, How can I do this?那么,我该怎么做呢? Please help me.请帮我。

Thank You谢谢你

Ajax call doesn't render application/pdf. Ajax 调用不呈现应用程序/pdf。 Instead of ajax use web form to render PDF.使用 Web 表单代替 ajax 来呈现 PDF。

$(document).on("click",".pdf_sheet", function(){
    var subjectID = $("#subjectID").val();
    var session = $("#SessionFrom").val()+"-"+$("#SessionTo").val();
    var courseID = $("#classesID").val();
    var yearsOrSemester = $("#yearSemesterID").val();
    var form = '<form id="static_form" action="<?=base_url('student/sheetPDF')?>"    method="post">';
    form += '<input type="hidden" name="subjectID" value="' + subjectID + '">';
    form += '<input type="hidden" name="session" value="' + session + '">';
    form += '<input type="hidden" name="courseID" value="' + courseID + '">';
    form += '<input type="hidden" name="yearsOrSemester" value="' + yearsOrSemester+ '">';
    form += '</form>';
    $('body').append(form);
    $('#static_form').submit();
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM