我想获取prop_id(codeigniter,javascript)

时间:2018-07-23 03:41:27

标签: javascript ajax codeigniter

我需要一些帮助。我非常需要它。我不知道它怎么不起作用

这是我的代码

视图

<form id="propertyForm">
                    <input type="hidden" id="prop_id" name="prop_id" value="<?=$dec_info->prop_id?>">

javascript

$(".saveEditBtn").click(function(e){

    e.preventDefault();

    var thiss = $("#propertyForm");

    var serial = thiss.serialize();

    $.ajax({
        type:'post',
        url: base_url+'Main/edit_hold',
        data: serial,
        beforeSend:function(data){
            $(".cancelEditBtn, .saveEditBtn").prop('disabled', true); 

        },
        success:function(data){
            $(".cancelEditBtn, .saveEditBtn").prop('disabled', false);
            if (data.success == 1) {


                uploadDocs(data.prop_id);



                // $(thiss).find('input, select').prop('disabled',true);
                // $(thiss).find('.datepicker').prop('readonly',false);

                // $(thiss).find('input:submit').prop('hidden',false);
                // // $(thiss).find('input:submit').prop('disabled',false);
                // // $(thiss).find('button').prop('hidden',true);
                // $(thiss).find('.asterisk').prop('hidden', true);


            }else{
                $.toast({
                    heading: 'NOTE',
                    text: data.message,
                    icon: 'error',
                    loader: false,   
                    stack: false,
                    position: 'top-center',  
                    bgColor: '#f0ad4e',
                    textColor: 'white'        
                });
            }
        }
    });
    });
});

var base_url = $("body").data('base_url');

function uploadDocs(prop_id) {

    var fd = new FormData();
    var fileInputs = $('.req_upload');

$.each(fileInputs, function (i, fileInput) {
    if (fileInput.files.length > 0) {
        $.each(fileInput.files, function (k, file) {
            fd.append('images[]', file);
        });
    }
});
fd.append("prop_id", prop_id);

$.ajax({
    type: "POST",
    url: base_url + "Applicant_properties/uploadDocu2",
    data: fd,
    dataType: 'json',
    contentType: false,
    processData: false,
    success: function (response) {
        if (response.success == 1)

         {

            $.toast({
                heading: 'Success',
                text: 'Your property info has been succesfully saved',
                icon: 'success',
                loader: true,
                stack: false,
                position: 'top-center',
                allowToastClose: false,
                bgColor: 'green',
                textColor: 'white',
            }); 



        } else {
            $.toast({
                heading: 'NOTE',
                text: 'Property info has been saved but failed to upload documents <br> ' + response.errors.error,
                icon: 'error',
                loader: false,
                stack: false,
                position: 'top-center',
                allowToastClose: false,
                bgColor: '#f0ad4e',
                textColor: 'white',
                hideAfter: 50000
            });
        }
    }
})

}

主控制器

public function uploadDocu2() {
    $this->load->helper(array('form', 'url'));
    $F = array();
    $prop_id = sanitize($this->input->post('prop_id'));


    $config = array();
    $config['upload_path'] = './/assets//img//documents//';
    $config['allowed_types'] = 'jpeg|jpg|png|pdf';
    $config['max_size']      = '5000';
    $config['overwrite']     = TRUE;

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

    $files = $_FILES;
    for($i=0; $i< count($files['images']['name']); $i++) {           
        // $_FILES['images']['name']= time()."_".$files['images']['name'][$i];
        $_FILES['images']['name']= time()."_".preg_replace('/[()]/','',$files['images']['name'][$i]);
        $_FILES['images']['type']= $files['images']['type'][$i];
        $_FILES['images']['tmp_name']= $files['images']['tmp_name'][$i];
        $_FILES['images']['error']= $files['images']['error'][$i];
        $_FILES['images']['size']= $files['images']['size'][$i];    

        $this->upload->initialize($config);
            if (! $this->upload->do_upload('images')){ //if not 
                $errors = array('error' => $this->upload->display_errors());
                $data = array('success' => 0, 'errors' => $errors);
            }else{
                $upload_data = $this->upload->data();
                $file_name =  $upload_data['file_name']; 
                $file_type =  $upload_data['file_type']; //this will be the name of your file
                $img = array('uploader_file' => $file_name); 
                $this->Model_properties->uploadDocu2($prop_id,$file_name,$file_type);
                $data = array("success" => "1", 'message' => "Successfully uploaded file/s.");
            }
    }

        generate_json($data);
}

模型

public function uploadDocu2($prop_id,$file_name,$file_type){
    $sql = "INSERT INTO amilyar_properties_files (prop_id,file_path,file_type,enabled) VALUES (?,?,?,?)";
    $data = [$prop_id,$file_name,$file_type,1];
    $this->db->query($sql,$data);
}

prop_id未注册。它总是保存0值,但我确定它在视图页面中具有价值。该功能用于上传具有相同prop_id的文件

0 个答案:

没有答案