在codeigniter中使用ajax添加图像-不保存数据

jvidinwx  于 2021-06-18  发布在  Mysql
关注(0)|答案(0)|浏览(352)

我需要你的帮助,在下面的代码,花了寻找解决方案,没有一个是有用的,当我试图保存不保存在数据库中的任何东西,你能帮我吗。
这是我的观点

<div class="modal fade" id="add_modal_para" tabindex="-1" role="dialog" aria-labelledby="title" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="title" style="font-weight: 700;">Agregar</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Close">
          <span aria-hidden="true">&times;</span>
        </button>
      </div>

      <div class="modal-body">
      <form method="post" id="form_add_para" enctype="multipart/form-data">
        <div class="input-group mb-3">
            <div class="input-group-prepend">
                <span class="input-group-text" id="basic-addon1"><i class="fas fa-poop"></i></span>
            </div>
                <input type="text" name="txt_firtsname_para" id="txt_firtsname_para" class="form-control" placeholder="Nombres" maxlength="50" aria-label="Nombres" aria-describedby="basic-addon1" data-validation-error-msg-container="#txt_firtsname-error-dialog" data-validation="required custom length" data-validation-regexp="^[a-zA-Z\s]+$" data-validation-length="min3" data-validation-length="max50">
        </div>
                <div id="txt_firtsname-error-dialog"></div>

        <div class="input-group mb-3">
            <div class="input-group-prepend">
                <label for="txt_avatar">Imagen</label>
            </div>
                <input type="file" class="form-control-file" id="txt_avatar_para" name="txt_avatar_para">
        </div>

      </div>
          <div class="modal-footer">
            <button type="submit" id="btn_add_para" class="btn btn-success"><i class="fas fa-save"></i> Guardar</button>
            <button type="button" class="btn btn-secondary" data-dismiss="modal"><i class="fas fa-sign-in-alt"></i> Cerrar</button>
          </div>
      </form>

    </div>
  </div>
</div>

这是我的ajax代码

$('#submit').submit(function(e){
            e.preventDefault(); 
                 $.ajax({
                     url: baseurl+'app/Paramilitar/add_Para',
                     type: "POST",
                     data: new FormData(this),
                     dataType: "JSON",
                     processData:false, 
                     contentType:false,
                     cache:false,
                     async:false,
                     success: function(data){
                        $("#form_add_para")[0].reset();
                        $('#add_modal_para').modal('hide');
                        show_para_table();
                   }
                 });
            });

这是我的控制器

public function add_Para(){ 
    $config['upload_path']='./assets/uploads/';
        $config['allowed_types']='jpeg|jpg|png';
        $config['encrypt_name'] = TRUE;

        $this->load->library('upload', $config);

        if($this->upload->do_upload('txt_avatar_para'))
        {
        $data_ima = array('upload_data' => $this->upload->data());

        $data_person = array(
        'id_person_type' => '3',
        'firtsname' => $this->input->post('txt_firtsname_para'),
        'avatar' => $data_ima['upload_data']['file_name'],
        'active' => '1'
        );  

        $data_result= $this->Person_model->Insert_Person($data_person);
        echo json_encode($data_result); 
        }

这是我的模型示例:
公共函数insert\u person($data\u person){$data\u result=$this->db->insert('tbl\u person',$data\u person);返回$data_result;}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题