0

I have develop ajax upload with upload library in coodeigniter.

This is the data that I grab with jquery :

        var inputFile = $('input#file');
        var filesToUpload = inputFile[0].files;
        // make sure there is file(s) to upload
        if (filesToUpload.length > 0) {
            // provide the form data that would be sent to sever through ajax
            var formData = new FormData();

            for (var i = 0; i < filesToUpload.length; i++) {
                var file = filesToUpload[i];
                formData.append("file[]", file, file.name);
            }

This is my ajax :

$.ajax({
   url: "<?php echo base_url('surveyor/c_surveyor/add_file_image'); ?>",
   type: 'post',
   data: formData,
   processData: false,
   contentType: false,
   success: function () {
         $(":file").val('');
         $(":text").val('');
         $("#tableClean").find("tr:gt(0)").remove();
         $("#tableReport").find("tr:gt(0)").remove();
         $("#addRow").attr("disabled", false);
         $("#addClean").attr("disabled", false);

         $('#pilih_isotank').after('<div class="callout callout-success lead" id="div_error"><p id="pesan_error">Semua Data Berhasil Terupload</p></div>');
         $('#div_error').fadeIn("fast");
         $('#pesan_error').html(obj.Message);
         $('#div_error').fadeOut(7000);
         myArrays = [];
        }
});

I have a problem with this, how to pass another data in $ajax ilike this :

data: formData, EIR_REF : $('#no_eir').val();

I try to acces this EIR_REF like this on this url :

public function add_file_image(){
   echo $this->input->post('EIR_REF');
}

It gives me nothing. How can I make it true ?

2 Answers 2

1

formData.append will work as well. Just add the code below outside the loop before posting to server.

formData.append('EIR_REF', $('#no_eir').val());
Sign up to request clarification or add additional context in comments.

Comments

0

You can pass the formdata in a separate field and the extra field can append as shown below. And in the serever side you can access accordingly. Try this:

data: {formData:formData, EIR_REF : $('#no_eir').val()};

2 Comments

Please, explain your answer.From review.
it gives me result of echo is ["index.html"]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.