dougong9987 2016-10-17 10:46
浏览 36

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.

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥20 matlab计算中误差
    • ¥15 对于相关问题的求解与代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料
    • ¥15 使用R语言marginaleffects包进行边际效应图绘制
    • ¥20 usb设备兼容性问题
    • ¥15 错误(10048): “调用exui内部功能”库命令的参数“参数4”不能接受空数据。怎么解决啊