title: Call function inside CodeIgniter's controller using jquery / ajax
body: <p>Can somebody please explain to me what is the right way to call a php function with jquery / ajax in Codeigniter. Right now, this code isn't working and i cant figure out whay. Note that admin.php controler is inside admin map. Thanks in advance</p>
  
  <p>html code</p>
  
  <pre><code>&lt;form action="#" method="POST" id="change"&gt;
               &lt;input type="hidden" value="&lt;?php echo $row-&gt;id_product; ?&gt;" id="prod" &gt;    
               &lt;input type="submit" value="switch" &gt;
  &lt;/form&gt;
  &lt;div class="resultdiv"&gt;
      &lt;?php echo $data; ?&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>my function inside admin.php controller</p>
  
  <pre><code> public function do_search(){
          $id = $this-&gt;input-&gt;post('id');
          return $id;
      }
  </code></pre>
  
  <p>Jquery AJAX script</p>
  
  <pre><code>$( "#change" ).submit(function() {
    alert( "Change" );
    var id = $('#prod').val();
       $.ajax({
              type:'POST',
              url:'admin321/do_search',
              data:{'id':id},
              success:function(data){
                  $('#resultdiv').html(data);
              }
          });
  });
  </code></pre>
  
  <p>Config / routes.php</p>
  
  <pre><code>$route['admin/do_search'] = "admin_controller/admin/do_search";
  </code></pre>