title: JQuery AJax on CodeIgniter: JSON datatype returning null
body: <p>I'm new to codeigniter and it's my first time working with jquery ajax.</p>
  
  <p>I have a modal form that passes information to a script on the view. The problem I have is that the ajax is giving null values...<br>
  I tried to alert the data on the script and it is displaying the proper values, but when it passes the data as a json to the controller, I think that's where it's failing. I don't know what to do. Do you have any idea?</p>
  
  <p>snippet of the script on the view</p>
  
  <pre><code> $(function () { //add new user from modal
      $('#adduser_modal').modal('show');
      $('#adduser_modal').find('.modal-title').text('Add New User');
      $('#addUser_form').attr('action', '&lt;?php echo base_url() ?&gt;Hgv_controller/addnewuser');
  });
  $('#saveuser_btn').click(function () {
      var url = $('#addUser_form').attr('action');
      $.ajax({
          type: 'ajax',
          method: 'post',
          url: url,
          data: data,
          async: false,
          dataType: 'json',
          jsonpcallback: success
      :
      function (response) {
          if (response.success) {
              $('#adduser_modal').modal('hide');
              $('#addUser_form')[0].reset();
          }
      }
  });
  </code></pre>
  
  <p>here's a snippet of code from the controller</p>
  
  <pre><code>public function addnewuser()
  {
      $this-&gt;load-&gt;database();
      //load model for crud
      $this-&gt;load-&gt;model('Crud');
      $result = $this-&gt;Crud-&gt;adduser();
  
      $msg['success'] = false;
      $msg['type'] = 'add';
      if ($result) {
          $msg['success'] = true;
      }
      echo json_encode($msg);
  }
  </code></pre>
  
  <p>and here's a snippet from the model</p>
  
  <pre><code>public function adduser()
  {
      $field = array(
          'username' =&gt; $this-&gt;input-&gt;post('hgv_username'),
          'f_name' =&gt; $this-&gt;input-&gt;post('hgv_firstname'),
          'l_name' =&gt; $this-&gt;input-&gt;post('hgv_lastname'),
          'password' =&gt; $this-&gt;input-&gt;post('hgv_password'),
          'user_type' =&gt; $this-&gt;input-&gt;post('hgv_type'),
      );
      $this-&gt;db-&gt;insert('hgv_user', $field);
      if ($this-&gt;db-&gt;affected_rows() &gt; 0) {
          return true;
      } else {
          return false;
      }
  }
  </code></pre>