pdf ajax call with cakephp

Subject:

references:  http://business.cc/Transactions/view/7

you dono'don't load the data from the ajax.  just load an iframe with the src

2015-03-08 17:00:19gstlouis

$('.PDF-doc').on('click', function(){
    $.ajax({
        type: 'GET',
        url: "/transactions/file/<?php echo $tx['Transaction']['id_trans']; ?>",
        contentType: 'application/pdf',
        success: function(data){
            
            var iframe = $('<iframe>');
            iframe.attr("src","/transactions/file/<?php echo $tx['Transaction']['id_trans']; ?>");
            $('#PDF-reader').append(iframe);

            //new PDFObject($(data).html()).embed('#PDF-reader');
            //new PDFObject("/transactions/file/<?php echo $tx['Transaction']['id_trans']; ?>").embed('PDF-reader');
        },
        error: function(data){
            alert('There was a problem fetching the information.  Please contact the web administrator');
        }
    });//end of ajax

 

 

controller

 

public function file($id = null){

        //load PDF file for transaction

                $txfile = $this->Transaction->find('first', array(
                'conditions' => array('Transaction.id_trans' => $id)));

                //var_dump($tx['Transaction']['filename']);
                $this->view = 'media';
                $this->autoRender = false;
                $this->response->type('pdf');
            
            $this->response->header('Content-Disposition', 'inline', 'Content-type: application/pdf');

        $file = $this->response->file('/tmp/tests/'.$txfile['Transaction']['filename'].'');
        return $this->response;


    }

gstlouis
vote
2015-03-08 17:00:47