Send two dates as a parameter from javascript ajax

0

I have the following button which sends to a JS function and enters correctly

<button class="btn btn-primary" onclick="filtrar()"><i class="fa fa-filter"></i> Filtrar</button>

This is my JS function

var save_metodo; //guarda el metodo cadena
    var tabla;

    function filtrar() {
      save_metodo = 'filtrar';

      validar(save_metodo);
    }

    function validar($funcion) {
      var url;

      var txtDateInicio = document.getElementById('date_inicio').value;
      var txtDateFin = document.getElementById('date_fin').value;
   
      //var banderaRBTN = false;
    
      //Test campo obligatorio
      if(txtDateInicio === '' && txtDateFin === ''){
        alert('esta vacio');
        //return false;
      } else{
        if ($funcion === 'filtrar') {
          url = "<?=base_url('index.php/login_controller/perfil_calls')?>/";
          alert(url);
        }else if ($funcion === 'export_pdf') {
          url = "<?=base_url('index.php/login_controller/generar_pdf/')?>";
        } else {
          url = "<?=base_url('index.php/login_controller/gererar_excel')?>";
        }

        // ajax
          $.ajax({
            url : url,
            type: "POST",
            dataType: "JSON",
            success: function(data) {
               location.reload();
            },
            error: function (jqXHR, textStatus, errorThrown) {
                alert('Error al filtrar');
            }
        });

      }

    }

I need to send the URL variable txtDateHome and txtDateFin as parameter but it is not running, it is entering the error.

My controller function where I should receive the dates as a parameter (it does not necessarily have to be as parameter).

public function perfil_calls($date_inicio, $date_fin) {
  $data = array();
  $data['calls'] = $this->login_model->rango_calls($date_inicio, $date_fin);

  $this->load->view('perfil_view.php', $data);
}

I hope you can help me.

Thanks

    
asked by Javier fr 09.07.2018 в 21:56
source

0 answers