在codeigniter中发布500(内部服务器错误)ajax

时间:2017-11-17 10:11:35

标签: ajax codeigniter post internal-server-error

我有一个问题,用ajax发送数据,当我点击按钮保存到发送数据到数据库。但是当我按F12时错误显示

POST http://[::1]/sys-web/admlogin/manufacture/addmanufacture 500 (Internal Server Error)
send @ http://[::1]/sys-web/assets/js/jquery-2.1.4.min.js:4
ajax @ http://[::1]/sys-web/assets/js/jquery-2.1.4.min.js:4
save @ http://[::1]/sys-web/admlogin/manufacture:374
onclick @ http://[::1]/sys-web/admlogin/manufacture:507

CI控制器

public function AddManufacture()
{

    $data = array(

        'manufacturing_name' => $this->input->post('manufacturing_name'),
        'address' => $this->input->post('address'),
        'email' => $this->input->post('email'),
        'telephone' => $this->input->post('telephone'),
        'join_date' => $this->input->post('join_date')
    );
    $insert = $this->m_manufacture->save($data);

    echo json_encode(array("status" => TRUE));
}

CI模型:

function save($data)
    {
        $sql = $this->db->insert($this->table, $data);
        return $sql;
    }

CI视图:

    function save()
 save_method = 'add';
        {
            $('#btnSave').text('saving...'); //change button text
            $('#btnSave').attr('disabled',true); //set button disable
            var url;

            if(save_method == 'add') {
                url = "<?php echo site_url('admlogin/manufacture/addmanufacture')?>";
            } else {
                url = "<?php echo site_url('admlogin/manufacture/editmanufacture')?>";
            }

            // ajax adding data to database

            var formData = new FormData($('#form')[0]);
            $.ajax({
                url : url,
                type: "POST",
                data: formData,
                contentType: false,
                processData: false,
                dataType: "JSON",
                success: function(data)
                {

                    if(data.status) //if success close modal and reload ajax table
                    {
                        $('#modal_form').modal('hide');
                        reload_table();
                    }
                    else
                    {
                        for (var i = 0; i < data.inputerror.length; i++)
                        {
                            $('[name="'+data.inputerror[i]+'"]').parent().parent().addClass('has-error'); //select parent twice to select div form-group class and add has-error class
                            $('[name="'+data.inputerror[i]+'"]').next().text(data.error_string[i]); //select span help-block class set text error string
                        }
                    }
                    $('#btnSave').text('save'); //change button text
                    $('#btnSave').attr('disabled',false); //set button enable


                },
                error: function (jqXHR, textStatus, errorThrown)
                {
                    alert('Error adding / update data');
                    $('#btnSave').text('save'); //change button text
                    $('#btnSave').attr('disabled',false); //set button enable

                }
            });
        }

0 个答案:

没有答案