1

ファイルのダウンロードに codeigniter と ajax を使用しています。

私の Ajax リクエスト

    $('.exporter').bind('click',function()
    {
    var callfunction = 'reportprints/print_'+$(this).attr('id').toLowerCase();
    var Query = $('#exportQuery').val();                        
    $.ajax({
    url: callfunction,
    type: 'POST',           
    dataType: 'html',
    data:{q:Query},                                                         
    success: function(output)
    {}
    });
    });

コントローラーにあるPDF関数を呼び出しています

    public function print_pdf()
    {
        $Query = $this->input->post('q');
        // set document information
        $this->pdf->SetAuthor('PrimexOne Exchange');
        $filename = $this->makefilename('pdf','DSP');
        $this->pdf->SetTitle('Daily Sales Report - '.date('d/m/Y'));
        $this->pdf->SetSubject('PrimexOne Sales Report');
        $this->pdf->SetKeywords('keywords');        
        $this->pdf->SetFont('helvetica', 'N', 12);   
        // add a page
        //$this->pdf->AddPage();     
        // write html on PDF
        $this->pdf->Cell(0,10,'Welcome in PrimexOne');

        //Creating FileName

        $filepath = APPPATH.'cache/pdfcache/';
        $fullname = $filepath.$filename;
        $this->pdf->Output($fullname, 'F');     
        $this->downloadfile(array('format'=>'pdf','filename'=>$filename,'filepath'=>$fullname));            
    }

ajax と PHP は完全に実行され、pdfcache フォルダーに PDF が作成されます。問題は、ファイルの作成時にファイルがダウンロードされないことです。

ここに私のダウンロードスクリプトがあります

    public function downloadfile($arr)
    {

         $mime = 'application/force-download';
           header('Pragma: public');    
           header('Expires: 0');        
           header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
           header('Cache-Control: private',false);
           header('Content-Type: '.$mime);
           header('Content-Disposition: attachment; filename="'.$arr['filename'].'"');
           header('Content-Transfer-Encoding: binary');
           header('Connection: close');
           readfile($arr['filepath']);    
           exit();

    }   

天才が私の問題を理解してくれることを願っています

4

2 に答える 2

1

application/force-downloadは MIME タイプではありません。

試す

$mime = 'application/pdf';

$('.exporter').bind('click',function(){
    var Query = $('#exportQuery').val();
    var callfunction = 'reportprints/print_'+$(this).attr('id').toLowerCase();
    event.preventDefault();
    var newForm = $('<form>', {
        'action': callfunction,
        'target': '_top'
    }).append($('<input>', {
        'name': 'q',
        'value': Query,
        'type': 'hidden'
    }));
    newForm.submit();
});
于 2013-09-05T13:17:24.673 に答える
0

これを試して

window.location.replace('Your URL Here')

必要な変数を get に渡します。

通常のように見えますが、完全に機能します。

于 2013-09-05T14:55:45.190 に答える