doulutian4843 2018-12-01 17:11
浏览 42

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

I need your help in the following code, and spent looking for solutions and none is useful, when I try to save does not save anything in the database, could you help me.

This is my VIEW

    <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>

This is my AJAX code

$('#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();
                   }
                 });
            });

This is my CONTROLLER

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); 
        }     

This is my MODEL Model example:
public function Insert_Person($data_person) { $data_result= $this->db->insert('tbl_person',$data_person); return $data_result; }

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记
    • ¥15 保护模式-系统加载-段寄存器
    • ¥15 电脑桌面设定一个区域禁止鼠标操作
    • ¥15 求NPF226060磁芯的详细资料