在 codeigniter 中使用 ajax 的过滤器不起作用

问题描述 投票:0回答:0

我在 codeigniter 中使用 ajax 创建了一个简单的过滤器,该过滤器是一个复选框,用户可以在其中选择多个值,我的视图如下所示:

$(document).ready(function() {
        $('[name=types]').click(function(){

             $.ajax({
                url: '<?php echo base_url()?>homecontroller/filterp',
                type: 'POST',
                data: {types: $('input[name="types"]:checked')},
                error: function() {
                   alert('Something is wrong');
                },
                success: function(data) {
                  
                  $('#marble').html(data);
                }
             });
           });
    });
<div class="tm-form-field" id="p1">
  <?php foreach($types as $my1){?>
  <div>
    <input type="checkbox" name="types[]" value="<?=$my1->id?>" id="ty<?=$my1->id?>">
    <label for="ty<?=$my1->id?>"><?=$my1->name?></label>
  </div>
  <?php } ?>
</div>

我的控制器和模型是这样的:

public function filterp() {
  $types=$this->input->post('types');


    $data = $this->product->filterp($types);

    foreach($data as $product) {
    
    .......
    ......
    .....
    
    }

   function filterp($types)
      {
       
        $this->db->where_in('types', $types);


          return $this->db->get('product')->result();
      }

然而,当复选框被选中时这不起作用并且我没有收到任何错误,任何人都可以告诉我这里有什么问题,提前感谢

php jquery ajax codeigniter codeigniter-3
© www.soinside.com 2019 - 2024. All rights reserved.