codeigniter复选框过滤

时间:2016-05-04 10:18:05

标签: php codeigniter

嗨我想在codeigniter中复选框过滤...但它显示输出不正确...如果有人知道这一点请尝试解决此问题

这是我的控制器

<?php  
class Check extends CI_Controller {
  public function laptops(){
    $this->load->model('check_m');
    $filter = array(
        'price' => $this->input->get('price'),
        'name' =>$this->input->get('name')
    );
    $data['laptop'] = $this->check_m->laptops_m($filter);

   // echo json_encode( $data['laptop'] );
   $this->load->view('check_view',$data);
 }
}
?>

型号:

<?php
class check_m extends CI_Model {
  function laptops_m($filter = null){
    $this->db->select('*')
             ->from('mobile_phones');
    // $query = $this->db->get('laptop_notebook')->result();
    // return $query;
    if($filter['name']){
      $this->db->where('name', $filter['name']);
    }
    if($filter['price']){
      $this->db->where('price', $filter['price']);
    }
    $query = $this->db->get()->result();
    return $query;
  }  
}
?>

查看

<input type="checkbox" name="name" value="acer" class="searcType">      
<input type="checkbox" name="name" value="lenovo">    
<input type="checkbox" name="price" value="1000">   
<table>
  <tbody>
    <?php foreach ($laptop as $laptops_all) { ?>
      <tr>
        <td><p>Laptop <?php echo $laptops_all->name ?> </p></td>
      </tr>
    <?php } ?>
  </tbody>
</table>  

<script>  
  $('.searchType').click(function() {
    alert($(this).attr('id'));  //-->this will alert id of checked checkbox.
    if(this.checked){
      $.ajax({
        url: localhost/code/check/laptops,
        dataType: 'json',
        success: function(data){
          $.each(data, function(index, element) {
            $("tbody").empty();
            $("tbody").append("<tr><td>"+
              "Laptop "+element.brand+""+
              "</td></tr>");
            });
          }
      }); 
    }
  });
</script>

这里我想用复选框过滤项目......但我没有得到过滤输出....

1 个答案:

答案 0 :(得分:0)

您没有发送 $ this-&gt; input-&gt; get()的任何参数来接收。

如果您只是发送 GET 请求,则无需像评论中提到的那样发送 csrf_token

您可能需要先检查/设置一些配置变量。 它们位于 application / config / config.php

$config['uri_protocol'] = 'QUERY_STRING'; // OR AUTO
$config['allow_get_array'] = TRUE;
$config['enable_query_strings'] = TRUE;
var BASEHREF = "<?php echo base_url();?>";

您的ajax选项应包含以下内容

{
   url  : BASEHREF + 'check/laptops',
   type : 'GET',
   data : { name : 'toshiba', price : '1000'}
}
// GET http://yoursite.com/check/laptops?name=toshiba&price=1000
相关问题