Q:

how pass file value with this jquery code

my code
if (submitType == "add") {
    url = "<?php echo base_url();?>admin/packages/add";
} else {
    url = "<?php echo base_url();?>admin/packages/manage/" + slug;
}

$.post(url, $(".package-form").serialize(), function(response) {
    if ($.trim(response) != "done") {
        $(".output").html(response);
    } else {
        window.location.href = "<?php echo base_url().$adminsegment." / packages / "?>";
    }
});

I have an input file named pdfupload in a form, that value not getting in controller action. anybody knows how to pass that, please help me

A:

Use $.ajax instead of $.post
$('#form_id').submit(function(){
var formData = new FormData(this);

$.ajax({
                type:'POST',
                url: url,
                data:formData,
                cache:false,
                contentType: false,
                processData: false,
                success:function(success){
                    //success
                }
});
});

Dont forget to add enctype in form as enctype="multipart/form-data"
This will solve your problem.

