Search code examples
phpjqueryajaxcodeignitercodeigniter-2

How to retrieve parameter passed from ajax to controller in Codeigniter


I want to retrieve parameter passes from ajax in Controller in Codeigniter but did not know how to use it my ajax function is below

function sendVideoData(frm_id)
{

    var data = new FormData(document.getElementById("post_video_"+frm_id));

    // make the AJAX request
    jQuery.ajax({
        type: "POST",
        url: "<?php echo base_url(); ?>"+"dashboard/do_upload",
        data: data+'&form_id='+frm_id,
        mimeType:"multipart/form-data", 
        contentType: false,
        cache: false,
        processData:false,
        dataType: 'json',
        success: function (data) {
          alert(data);
        },

    });

    return false;
}
</script>

I want to retrieve

form_id

in my controller and use it


Solution

  • It's pretty simple,

    echo $this->input->post('form_id')

    or simple php

    echo $_POST['form_id']

    inside your controller dashboard and method do_upload

    You can get all list of post variables using print_r($this->input->post()) as well.