Ajax或数据库无法正常工作

I have been struggling for days. I am doing ajax callback by assigning an input field but I am unable to too. Below is the code:

Script

$('[name="acccode[]"]').each(function(idx,val){
var acccode = $('[name="acccode[]"]').eq(idx).val();
console.log(acccode);
$.ajax({
  url : "<?php echo base_url(); ?>readacccode",
  type: "POST",
  data:"Acc_Code="+acccode,
  dataType: "JSON",
  success: function(data)
  {
    $.each(data.results,function(idx,val){
    console.log(val);
    $('[name="accname[]"]').val(val);
  });
  },
  error: function (data)
  {
      swal("Oops", "We couldn't connect to the server!", "error");
  }
 });
 });

I am successfully able to get each acc code. But not the name.

Here is the Controller code:

  public function readacccode()
  {
    if (!$this->ion_auth->logged_in() || $this->ion_auth->is_store())
    {
         redirect('account/login');
    }
        $acccode = $this->input->post('acccode');
        $data['results']=$this->Setting->get_acccode($acccode);
        echo json_encode($data);
}

it is getting the acc name where the acc code matches.

Please advise.

Thanks, everyone the problem is resolved. For those wanting to know here is the thing I change.

public function readacccode()
{
if (!$this->ion_auth->logged_in() || $this->ion_auth->is_store())
{
     redirect('account/login');
}
    $acccode = $this->input->post('Acc_Code'); //All I did is replace acccode to Acc_Code
    $data['results']=$this->Setting->get_acccode($acccode);
    echo json_encode($data);
}