Pass data to the Controller and Open new Window in Codeigniter [Not working]

0

[EDITED]

I am trying to pass the entered value of two fields, date_ini and date_ter, I believe that the data is sent since the success is now executed, that is, a new tab that would be > C_Porce_PDF . However, when loading it, it shows me an error that the parameters have not been passed. Any help is welcome.

Javascript

$(document).ready(function(){

 $("#btn_buscar").click(function(evento){


    var fecha_ini =  $("#fecha_ini").val();
    var fecha_ter =  $("#fecha_ter").val();

    $.ajax({

      url: "<?php echo base_url(); ?>" + "C_Porcentaje_PDF/tabla_porcentaje/",
      type: 'post',
      data: { "fecha_ini": fecha_ini, "fecha_ter": fecha_ter },

        success: function(response){ 

           //alert($("#fecha_ini").val());
           window.open('<?php echo base_url();?>C_Porcentaje_PDF/tabla_porcentaje/', '_blank');
         }

    });

  });

 });

Controller

public function index(){


 $this->load->model('M_Porcentaje_PDF');

 $data['consulta'] = $this->M_Porcentaje_PDF->tabla_porcentaje();
 $this->load->view('usuarios/test.php',$data);



}

   public function tabla_porcentaje(){


   $fecha_ini = $this->input->post('fecha_ini');
   $fecha_ter = $this->input->post('fecha_ter');
   $this->load->model('M_Porcentaje_PDF');
   $this->M_Porcentaje_PDF->tabla_porcentaje($fecha_ini, $fecha_ter);



}

Model

public function tabla_porcentaje ($fecha_ini, $fecha_ter){

$start ="$fecha_ini 08:30:00 ";
$end = "$fecha_ter 22:30:00 ";

$this->db->select('motivos_citas.descripcion_mot,COUNT(*) AS cantidad_motivos, (SELECT COUNT(motivos_citas.descripcion_mot)* 100 / COUNT(citas.id_ci) FROM citas AS citas WHERE citas.fecha_ini BETWEEN "$start" AND "$end" ) AS porcentaje');
$this->db->from('citas');
$this->db->join('motivos_citas','citas.id_mot=motivos_citas.id_mot');
$this->db->where('citas.fecha_ini BETWEEN "$start" AND "$end" ');
$this->db->group_by('motivos_citas.descripcion_mot');
$consulta = $this->db->get();

if($consulta->num_rows() > 0 ){

return $consulta->result();

   }
 }

}

View with the result

 <html>


 <head>
 <link href="<?php echo base_url();?>assets/img/logo-32.ico" type="image/x-icon" rel="shortcut icon" />
 <title>Porcentaje de Cias</title>
 </head>

 <body>

   <h2 style="text-align:center;">Porcentaje de Citas</h2>
   <br></br>
   <br></br>
<div style="top: -100px;">
 <table style="border:1px solid red;width:100%;">
 <tr>
    <th style="text-align:center;">Motivo</th>
    <th style="text-align:center;">Cantidad</th>
    <th style="text-align:center;">Porcentaje</th>
 </tr>
           <?php foreach($consulta as $row){?>

           <tr>
              <td style="text-align:center;"><?php echo $row->descripcion_mot ;?></td>
              <td style="text-align:center;"><?php echo $row->cantidad_motivos ;?></td>
              <td style="text-align:center;"><?php echo $row->porcentaje ;?></td>


           </tr>

       <?php }?>
     </table>
    <div>

  </body>

  </html>

ERROR

  An uncaught Exception was encountered

  Type: ArgumentCountError

  Message: Too few arguments to function M_Porcentaje_PDF::tabla_porcentaje(), 0 passed in C:\xampp\htdocs\SAE\application\controllers\C_Porcentaje_PDF.php on 
  line 21 and exactly 2 expected
    
asked by CristianOx21 16.10.2017 в 15:09
source

1 answer

0

tries this way the ajax

var base_url = "<?= base_url()?>";//with or without index.php
$.ajax({
                    type: "POST",
                    url: base_url + 'C_Porcentaje_PDF/tabla_porcentaje',
                    data: $("#form_id").serialize();
                    beforeSend: function( ) {
                            console.log('before');
                    },
                    success: function( data ) {
                            console.log('success');
                            console.log(data);
                    },
                    error:function( e ) {
                        $("#loading").hide();
                            console.log('error');
                            console.log(e);
                    }
            });

and in your controller comment everything and just have this

public function tabla_porcentaje(){
foreach($this->input->post() as $item => $value){
    ${$item} = $value;
    echo $item . ' - ' . $value . '<br>';
    log_message('error', 'DEBUG VALUES : ' . $item . ' -> ' . $value);
}
die();
 $data = array(
 'fecha_ini' => $this->input->post('fecha_ini'),
 'fecha_ter' => $this->input->post('fecha_ter'),
);

 $this->load->model('M_Porcentaje_PDF');
 $this->M_Porcentaje_PDF->tabla_porcentaje($data);
}

and tell me if this solves the problem of sending information from ajax to the controodr

    
answered by 16.10.2017 в 20:12