title: How to call a Codeigniter function with _remap function from an ajax url?
body: <p>I'm working on ajax datatable and when I tried to load the page I got an error </p>
  
  <p><em>Datatables warning table id=table - invalid JSON response</em></p>
  
  <p>I figured out that it has something to do with the ajax url from datatable seems like it can't locate the controller function that should be loaded.</p>
  
  <p>I'm using a <code>_remap()</code>function on my controller that's why I think it's having conflict with urls and my function can't be called.</p>
  
  <p><strong>This is my controller:</strong></p>
  
  <pre><code>&lt;?php
  
  defined('BASEPATH') OR exit('No direct script access allowed');
  
  class Requests extends CI_Controller {
  var $pgToLoad;
  
  public function __construct() {
      parent::__construct();
      #this will start the session
      session_start();
  
      if(!isset($_SESSION['userId']) || !isset($_SESSION['userLevel']) || !isset($_SESSION['employeeid']) || !isset($_SESSION['firstname']) || !isset($_SESSION['lastname'])) {
          redirect('home', 'location');
      }
  
      #this will load the model
      $this-&gt;load-&gt;model('Contents');
  
      #get last uri segment to determine which content to load
      $continue = true;
      $i = 0;
      do {
          $i++;
          if ($this-&gt;uri-&gt;segment($i) != "") $this-&gt;pgToLoad = $this-&gt;uri-&gt;segment($i);
          else $continue = false;             
      } while ($continue);        
  }
  
  public function index() {   
      $this-&gt;load-&gt;helper('url'); 
      $this-&gt;main();
  
  }   
  
  public function main() {
      #set default content to load 
      $this-&gt;pgToLoad = empty($this-&gt;pgToLoad) ? "Requests" : $this-&gt;pgToLoad;
      $disMsg = "";
  
      #this will delete the record selected
      if($this-&gt;uri-&gt;segment(2) == 'leave') { 
          $this-&gt;leave();
      }
  
      #this will logout the user and redirect to the page
      if($this-&gt;uri-&gt;segment(2) == 'logout') {
          session_destroy();
          redirect('home', 'location');
      }                   
  
      $data = array ( 'pageTitle' =&gt; 'Payroll System | ADMINISTRATION',
                      'disMsg'    =&gt; $disMsg,                                             
                      'mainCont'  =&gt; $this-&gt;mainCont );
  
      $this-&gt;load-&gt;view('mainTpl', $data, FALSE);
  }
  
  
  
      public function ajax_list()
  {
      $list = $this-&gt;Contents-&gt;get_datatables();
      $data = array();
      $no = $_POST['start'];
      foreach ($list as $leave) {
          $no++;
          $row = array();
          $row[] = $leave-&gt;id;
          $row[] = $leave-&gt;type;
          $row[] = $leave-&gt;startdate;
          $row[] = $leave-&gt;enddate;
          $row[] = $leave-&gt;duration;
          $row[] = $leave-&gt;reason;
          $row[] = $leave-&gt;status;      
  
          //add html for action
          $row[] = '&lt;a class="btn btn-sm btn-primary" href="javascript:void(0)" title="Edit" onclick="edit_person('."'".$leave-&gt;id."'".')"&gt;&lt;i class="glyphicon glyphicon-pencil"&gt;&lt;/i&gt; Edit&lt;/a&gt;
                &lt;a class="btn btn-sm btn-danger" href="javascript:void(0)" title="Hapus" onclick="delete_person('."'".$leave-&gt;id."'".')"&gt;&lt;i class="glyphicon glyphicon-trash"&gt;&lt;/i&gt; Delete&lt;/a&gt;';
  
                $data[] = $row;
  
  
      }
  
      $output = array(
                      "draw" =&gt; $_POST['draw'],
                      "recordsTotal" =&gt; $this-&gt;Contents-&gt;count_all(),
                      "recordsFiltered" =&gt; $this-&gt;Contents-&gt;count_filtered(),
                      "data" =&gt; $data,
              );
      //output to json format
      echo json_encode($output);
  }
  
  #this will display the form when editing the product
  public function leave() {
  
  
      $data['employee'] = $this-&gt;Contents-&gt;exeGetEmpToEdit($_SESSION['userId']);  
          $this-&gt;mainCont = $this-&gt;load-&gt;view('pages/requests/leave', '', TRUE);  
  
  }
   public function _remap () {
      $this-&gt;main();
  }
  </code></pre>
  
  <p><strong>Ajax datatable code</strong></p>
  
  <pre><code> $(document).ready(function () {
  
     //datatables
  table = $('#table').DataTable({
  
      "processing": true, //Feature control the processing indicator.
      "serverSide": true, //Feature control DataTables' server-side processing mode.
      "order": [], //Initial no order.
  
      // Load data for the table's content from an Ajax source
      "ajax": {
          **"url": "&lt;?php echo site_url('requests/leave')?&gt;",
          "type": "POST"
      },
  
      //Set column definition initialisation properties.
      "columnDefs": [
      {
          "targets": [ -1 ], //last column
          "orderable": false, //set not orderable
      },
      ],
  
  });
  </code></pre>
  
  <p>What's supposed to be the solution in this case? Thank you</p>