Php Ajax/JQuery日期范围搜索单击功能在Codeigniter上不起作用

Php Ajax/JQuery日期范围搜索单击功能在Codeigniter上不起作用,php,jquery,ajax,codeigniter,Php,Jquery,Ajax,Codeigniter,我正在尝试使用Ajax/JQuery在Codeigniter上通过日期范围搜索打印到pdf,我只是从internet获取代码并将其转换为Codeigniter,但当我单击打印按钮时,什么也没有发生 大部分代码都是来自互联网的,还在学习如何编码,请大家帮忙 Print_model.php <?php defined('BASEPATH') OR exit('No direct script access allowed'); class Print_model extends CI_Mod

我正在尝试使用Ajax/JQuery在Codeigniter上通过日期范围搜索打印到pdf,我只是从internet获取代码并将其转换为Codeigniter,但当我单击打印按钮时,什么也没有发生

大部分代码都是来自互联网的,还在学习如何编码,请大家帮忙

Print_model.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Print_model extends CI_Model {
function getPrint($id)
{
    $query = $this->db->query('SELECT * FROM loadsheet WHERE `id` ='.$id );
    return $query->row();
}
function getAllData() {
    $query = $this->db->query('SELECT * FROM loadsheet');
    return $query->result();
}

}
        <?php
    defined('BASEPATH') OR exit('No direct script access allowed');

    class PrintController extends CI_Controller {
        public function __construct() {
            parent::__construct();
            $this->load->model('Print_model');
        }
        public function index() 
        {
            $data['result'] = $this->Print_model->getAllData();
            $this->load->view('printView', $data);
        }
        public function generate_pdf() {
            //load pdf library
            $this->load->library('Pdf');
            $this->load->helper('url');

            $pdf = new Pdf(PDF_PAGE_ORIENTATION, PDF_UNIT, PDF_PAGE_FORMAT, true, 'UTF-8', false);
            $width = 175;  
            $height = 266; 
            $orientation = ($height>$width) ? 'P' : 'L';  

            // set document information
            $pdf->SetCreator(PDF_CREATOR);

            $pdf->SetTitle('');


            // set default header data
            //$pdf->SetHeaderData(PDF_HEADER_LOGO, PDF_HEADER_LOGO_WIDTH, PDF_HEADER_TITLE, PDF_HEADER_STRING);

            // set header and footer fonts
            $pdf->setHeaderFont(Array(PDF_FONT_NAME_MAIN, '', PDF_FONT_SIZE_MAIN));
            $pdf->setFooterFont(Array(PDF_FONT_NAME_DATA, '', PDF_FONT_SIZE_DATA));

            // set default monospaced font
            $pdf->SetDefaultMonospacedFont(PDF_FONT_MONOSPACED);

            // set margins
            $pdf->SetMargins(10, PDF_MARGIN_TOP, 10, true);
            $pdf->SetHeaderMargin(PDF_MARGIN_HEADER);
            $pdf->SetFooterMargin(PDF_MARGIN_FOOTER);

            // set auto page breaks
            $pdf->SetAutoPageBreak(TRUE, PDF_MARGIN_BOTTOM);

            // set image scale factor
            $pdf->setImageScale(PDF_IMAGE_SCALE_RATIO);

            // set font
            $pdf->SetFont('times ', 'B', 9);

            // ---------------------------------------------------------


            //Generate HTML table data from MySQL - start
            $template = array(
                'table_open' => '<table border="1" cellpadding="6" cellspacing="2" table-responsive>'
            );

            $this->table->set_template($template);

            $this->table->set_heading('Loadsheet No.', 'Date', 'Fuel Price', 'Location', 'Distance', 'Transport', 'Total Loadout', 'Total RGBF', 'Total Empties', 'Excess', 'Total Amount');

            $salesinfo = $this->Crud_model->get_salesinfo();

            foreach ($salesinfo as $sf):
                $this->table->add_row($sf->loadsheetNo, $sf->date, $sf->fuelprice, $sf->location, $sf->kmDistance, $sf->transportType, $sf->totalLoadOut, $sf->totalRGBF, $sf->totalEmpties, $sf->excess, $sf->totalAmount);
            endforeach;

            $html = $this->table->generate();
            //Generate HTML table data from MySQL - end

            // add a page
            $pdf->AddPage('L');

            // output the HTML content
            $pdf->writeHTML($html, true, false, true, false, '');

            // reset pointer to the last page
            $pdf->lastPage();
            ob_end_clean();
            //Close and output PDF document
            $pdf->Output(md5(time()).'.pdf', 'D');
        }

        function fetch()
     {
        if(isset($_POST["from_date"], $_POST["to_date"]))  
        {  
             $output = '';    
             $query = "SELECT * FROM loadsheet WHERE date BETWEEN '".$_POST["from_date"]."' AND '".$_POST["to_date"]."'  ";  
             $result = mysqli_query($query);

      $output .= '
      <div class="table-responsive">
         <table class="table table-bordered table-striped">
          <tr>
           <th>Loadsheet No.</th>
           <th>Date</th>
           <th>Fuel Price</th>
           <th>Location</th>
           <th>Distance</th>
           <th>Transport</th>
           <th>Total Loadout</th>
           <th>Total RGBF</th>
           <th>Total Empties</th>
           <th>Excess</th>
           <th>Excess</th>
           <th>Total Amount</th>
          </tr>
      ';
      if($data->num_rows() > 0)
      {
       foreach($data->result() as $row)
       {
        $output .= '
          <tr>
          <td>'.$row["loadsheetNo"].'</td>
          <td>'.$row["date"].'</td>
          <td>'.$row["fuelprice"].'</td>
          <td>'.$row["location"].'</td>
          <td>'.$row["kmDistance"].'</td>
          <td>'.$row["transportType"].'</td>
          <td>'.$row["totalLoadOut"].'</td>
          <td>'.$row["totalRGBF"].'</td>
          <td>'.$row["totalEmpties"].'</td>
          <td>'.$row["excess"].'</td>
          <td>'.$row["totalAmount"].'</td>
          </tr>
        ';
       }
      }
      else
      {
       $output .= '<tr>
           <td colspan="5">No Data Found</td>
          </tr>';
      }
      $output .= '</table>';
      echo $output;
     }
    }
    }
 <!DOCTYPE html>  
 <html>  
      <head>  
           <title>Print</title>  
           <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>  
           <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
           <script src="http://code.jquery.com/ui/1.10.3/jquery-ui.js"></script>  
           <link rel="stylesheet" href="http://code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">  
      </head>  
      <body>  
           <br /><br />  
           <div class="container" style="">  
                <h2 align="center">Please select date to print</h2>  

                <div class="col-md-3">  
                     <input type="text" name="from_date" id="from_date" class="form-control" placeholder="From Date" />  
                </div>  
                <div class="col-md-3" >  
                     <input type="text" name="to_date" id="to_date" class="form-control" placeholder="To Date" />  
                </div>  
                <div class="col-md-5">  
                     <input type="button" name="Print" id="printbtn" value="Print" class="btn btn-info" />  
                </div>  
                <div style="clear:both"></div>                 
                <br />  
                <table id="order_table" class="content-table"  style="width:100%">
            <thead class = "thead-dark">
                    <tr>
                    <th scope="col">ID</th>
                    <th scope="col">Date</th>
                    <th scope="col">Load Sheet No.</th>
                    <th scope="col">Fuel price</th>
                    <th scope="col">Location</th>
                    <th scope="col">Kilometer Distance</th>
                    <th scope="col">Transport Type</th>
                    <th scope="col">Total Load Out</th>
                    <th scope="col">Total RGB Fulls</th>
                    <th scope="col">Total Empties</th>
                    <th scope="col">Excess</th>
                    <th scope="col">Total Amount</th>

                    </tr>
                </thead>
                <tbody>
                    <?php foreach($result as $row){?>
                    <tr> 
                        <th> <?php echo $row->id; ?></th>
                        <td> <?php echo $row->date; ?></td>
                        <td><?php echo $row->loadsheetNo; ?></td>
                        <td><?php echo $row->fuelprice; ?></td> 
                        <td><?php echo $row->location; ?></td>
                        <td><?php echo $row->kmDistance; ?></td> 
                        <td><?php echo $row->transportType; ?></td> 
                        <td><?php echo $row->totalLoadOut; ?></td> 
                        <td><?php echo $row->totalRGBF; ?></td> 
                        <td><?php echo $row->totalEmpties; ?></td> 
                        <td><?php echo $row->excess; ?></td> 
                        <td><?php echo $row->totalAmount; ?></td>                             
                    </tr>
                    <?php } ?>
            </tbody>
        </table>   
                </div>  
           </div>  
      </body>  
 </html>  
 <script>  
      $(document).ready(function(){ 
           $.datepicker.setDefaults({  
                dateFormat: 'yy-mm-dd'   
           });  
           $(function(){  
                $("#from_date").datepicker();  
                $("#to_date").datepicker();  
           });  
           $('#printbtn').click(function(){  
                var from_date = $('#from_date').val();  
                var to_date = $('#to_date').val();  
                if(from_date != '' && to_date != '')  
                {  
                     $.ajax({  
                          url: "<?php echo site_url('printcontroller/generate_pdf');?>",  
                          type:'POST',  
                          data:{from_date:from_date, to_date:to_date},  
                          success:function(data)  
                          {  
                               $('#order_table').html(data);  
                          }  
                     });  
                }  
                else  
                {  
                     alert("Please Select Date");  
                }  
           });  
      });  
 </script>