title: Ajax on php with CI, gets undefined index term
body: <p>I am new in PHP, I followed a tutorial and in live search engine I got no result when typing charactors.I am suspicious to view index where I address source, but I am not sure. Sorry if the code is long!</p>
  
  <p>Controller product.php</p>
  
  <pre><code>    &lt;?php
  class Product extends CI_Controller {
      public function index(){
          $this-&gt;load-&gt;view('index');
            $this-&gt;load-&gt;model('mproduct');
           $result = $this-&gt;mproduct-&gt;search($_GET['term']);
            echo "this is search";
          if(count($result)&gt;0) {
              foreach ($result as $pr)
                  $arr_result[] = $pr-&gt;name;
          }
          echo json_encode($arr_result);
          }
  }
  </code></pre>
  
  <p>Model mproduct.php</p>
  
  <pre><code>&lt;?php
  class MProduct extends CI_Model 
  {
      function __construct() {
          parent::__construct();
      }
      function search($name) {
          $this-&gt;db-&gt;like('name',$name, 'both');
          return $this-&gt;db-&gt;get('product')-&gt;result();
  
      }
  }
  
  ?&gt;
  </code></pre>
  
  <p>view index.php</p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  &lt;html lang ="en"&gt;
      &lt;head&gt;
          &lt;link href="/phpAmir_contract/assets/css/jquery-ui.theme.min.css" type="text/css" rel="stylesheet"&gt;
          &lt;script type="text/css" src="/phpAmir_contract/assets/css/jquery-ui.min.css"&gt;&lt;/script&gt;
          &lt;script type="text/css" src="/phpAmir_contract/assets/css/jquery-ui.theme.min.css"&gt;&lt;/script&gt;
          &lt;script   type="text/javascript"   src="/phpAmir_contract/assets/js/jquery-1.4.2.js"&gt;&lt;/script&gt;
            &lt;script   type="text/javascript"   src="/phpAmir_contract/assets/js/jquery-ui.min.js"&gt;&lt;/script&gt;
          &lt;meta charset="utf-8"&gt;
  
  
          &lt;title&gt; demo&lt;/title&gt;
          &lt;script type="text/javascript"&gt;
          $(document).ready(function()){
              $('#production').autocomplete({
  
                  source: "/phpAmir_contract/application/controllers/product/search"
  
              })
          });
          &lt;/script&gt;
      &lt;/head&gt;
      &lt;body&gt;
  
          &lt;input type="text" name ="productname" id="productname"/&gt; 
  
      &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p><img src="https://i.stack.imgur.com/rtErw.png" alt="This is the error I get now"></p>