无法使用jQuery .ajax()向php codeIgniter发布选择多个

I'm trying to post multiple values of select element to php, which is giving error only in .ajax post. It works fine with HTML form post.

JS:

function serealizeSelects(select){
      var array = [];
      select.each(function(){ array.push($(this).val()) });
      return array;
    }

$("#go").on('click', function(e){
    e.preventDefault();
    if($("#title").val()=='') swal('','Please enter the title.','warning');
    else{
        $("#go").text('Publishing...');
        $("#go").prop('disabled',true);
        $.ajax({
          url: '<?=base_url();?>'+'classes/add_notes',
          type: "POST",
          data: {
            title: $("#title").val(),
            content: $("#content").val(),
            file: upFile,
            class: JSON.stringify(serealizeSelects($('.selectpicker'))),
            <?=$this->security->get_csrf_token_name();?>:'<?=$this->security->get_csrf_hash();?>',
          },
          dataType: "json",
          success: function(data){
            $("#go").text('Publish');
            $("#go").prop('disabled',false);
            if(data.error=='false'){
              swal('Published','Your notes has been shared to selected classes.');
            }
            else{
              if(data.error_code=='1') swal('','Please fill fields properly!','warning');
              else if(data.error_code=='2') swal('','Unauthorised','error');
              else swal('','Something went wrong','error');
            }
          },
          error: function(){
            $("#go").text('Publish');
            $("#go").prop('disabled',false);
            swal('','Some error occured','error');
          }
        });
      }
  });

HTML:

<select class="selectpicker" data-live-search="true" id="class" multiple>
       <option value="0">Choose classes...</option>
              <?=$classes;?>
 </select>

**PHP (CodeIgniter): **

$this->form_validation->set_rules('title', 'title', 'trim|required|xss_clean');
       $this->form_validation->set_rules('content', 'content', 'trim|xss_clean');
       $this->form_validation->set_rules('file', 'file', 'trim|xss_clean');
       $this->form_validation->set_rules('class[]', 'class', 'trim|required|xss_clean');

       if($this->form_validation->run() == FALSE OR $this->end!='teacher'){
         $response['error']="true";
         $response['error_code']="1";
       }
       else{
          $title=$this->input->post('title');
          $content=$this->input->post('content');
          $file=$this->input->post('file');
          $classes=json_decode($this->input->post('class[]'),true);
            foreach($classes as $class){
               // Some task
            }
      }

I've looked for lots of solution, none of which worked. I tried with class also, instead of class[]. Nothing worked! Posting this executes error part of ajax.

Do following changes:

<select class="selectpicker" data-live-search="true" id="class" multiple>

to

<select name="selectpicker[]" class="selectpicker" data-live-search="true" id="class" multiple>

and get its value like:

$this->input->post('selectpicker');

Explanation: For multi-select dropdown, its name must be and array like selectpicker[] so that it can hold multiple selected value in it and get its value by using its name in php.

You can never get a html element value in php using its class directly as you tried $this->input->post('class[]'),true);