500(内部服务器错误)使用jQuery $ .post与CodeIgniter

It is a widely asked question to help with this error but I have spent all day reading other answers and creating various versions for my code and still can not get anything else then this error. So I ask for your help.

My view:
<html>
<head>
  <title></title>
<?=$head?>
<script type="text/javascript" src="http://maps.google.com/maps/api/js?key=AIzaSyAhiKwDjhm1ZXS1jHBHErJf6pxT2TUCMM4"></script>
<script src="<?php echo base_url() ?>scripts/jquery.colorbox-min.js"></script>
<script src="<?php echo base_url() ?>scripts/gmaps.js"></script>
<link rel="stylesheet" href="<?php echo base_url() ?>css/colorbox.css">

  <style type="text/css">
    #map {
      width: 700px;
      height: 700px;
    }
  </style>
</head>
<body>
    <button id="go-button" type="button">Click Me!</button>

    <div class="multiselect">
        <label><input type="checkbox"  value="all" />All</label>
        <label><input type="checkbox" name="filtrs1[]" value="manufacturer1" />manufacturer1</label>
        <label><input type="checkbox" name="filtrs1[]" value="manufacturer2" />manufacturer2</label>
        <label><input type="checkbox" name="filtrs1[]" value="manufacturer3" />manufacturer3</label>
        <label><input type="checkbox" name="filtrs1[]" value="manufacturer4" />manufacturer4</label>
    </div>

  <div id="map"></div>
  <script type="text/javascript">
    var products= <?= json_encode($products);?>;
    var allMap;

    $(document).ready(function(){
        var allMap = new GMaps({
          el: '#map',
          zoom: 7,
          lat: 37.4419,
          lng: -122.1419
        });
        loadJsonMap(allMap, products);

        $('#go-button').click(function(){
            var chb = $("input[name='filtrs1[]']:checked");
            var filtrs1values = [];
            $.each(chb,function(){
              filtrs1values.push($(this).val());
            });
            $.post('<?php echo base_url() ?>index.php/products/filter', {
                    filtrs1 : filtrs1values
            }, function(response){
                allMap.removeMarkers();
                loadJsonMap(allMap, response);
            });
        });
    });

    function loadJsonMap(map, data){
            var markers_data = [];
            $.each(data, function(key, val){
                        if (val.latitude != undefined && val.longitude != undefined) {
                            markers_data.push({
                                lat : val.latitude,
                                lng : val.longitude,
                                details : {
                                    holder_id : val.holder_id
                                },
                                click : function(e){
                                    if(e.details.holder_id !== undefined){
                                        var url = '<?php echo base_url() ?>index.php/products/colorbox/' + e.details.holder_id;
                                        $.colorbox({
                                            open : true,
                                            href : url,
                                            iframe : false,
                                            innerWidth : 400,
                                            innerHeight : 400,
                                            close : 'Aizvert'
                                        });
                                    }
                                }
                            });
                        }
                    });
            map.addMarkers(markers_data);
    }
  </script>
</body>
</html>

where $.post calls for controller products:

public function filter()
        {
            $data['manufacturer'] = $this->input->post('filtrs1');

            $result = $this->products_model->get_productsByManufacturer($data);
            // $result = $this->security->get_csrf_token_name();
            // $result = $this->security->get_csrf_hash();
            header('Cache-Control: no-cache, must-revalidate');
            header('Content-Type: application/json');
            echo json_encode($result);
        }

where in products_model:

function get_productsByManufacturer($data)
        {
            if(empty($data['manufacturer']){
                $this->db->select("latitude,longitude, holder_id");
                $query = $this->db->get('products');
                return $query->result_array();
            }else{
                $this->db->select("latitude,longitude, holder_id");
                $this->db->where_in('manufacturer', $data['manufacturer']);
                $query = $this->db->get('products');
                return $query->result_array();
            }
        }

I get error on $.post line. I checked filtrs1values array using consule.log and got ["manufacturer3", "manufacturer4"]. Also I have changed my controller and model code multiple times but always get the same error.

dongxia527680
dongxia527680 你启用了csrf令牌吗?
大约 4 年之前 回复
dpvv37755
dpvv37755 感谢您的建议,我使用直接调用来查看php错误并修复它。每当我在模型中进行重大更改时,我都会创建它的副本。出于某种原因,我的控制器正在寻找products_model-copy。PHP。
大约 4 年之前 回复
donkey111111
donkey111111 用$.post('<?phpechobase_url(“index.php/products/filter”)替换“$.post('<?phpechobase_url()?>index.php/products/filter'”行?>'然后试试。我认为这是网址的问题
大约 4 年之前 回复
dpjjr42626
dpjjr42626 Jquery无法生成500错误,因为此错误是服务器端错误。错误在您的PHP代码中,它会生成500错误。它是引起它的被叫URL。如果你直接(或通过Postman)调用它会发生什么?
大约 4 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐