title: Uncaught SyntaxError: Unexpected token < in JSON at position 0 from Codeigniter response
body: <pre><code>&lt;option value="Petrol/Diesel"&gt;Petrol&lt;/option&gt;&lt;option
  value="Petrol/Diesel"&gt;Diesel&lt;/option&gt;
  </code></pre>
  
  <p>is the output generated when I see it in chrome>network. </p>
  
  <blockquote>
    <p>Cannot use 'in' operator to search for 'length' in </p>
  </blockquote>
  
  <p>Or I get above error. The code work fine and till the success inside the <code>&lt;script&gt;</code>, what am I doing wrong from here?</p>
  
  <pre><code>$.each(JSON.parse(result), function() {            
    $('#fuel').append(result);
  });  
  </code></pre>
  
  <p>Model:   </p>
  
  <pre><code>public function getFuel($modelid, $variant)
  {
    $query= "SELECT * FROM `pms_details` WHERE `model_id` = '".$modelid."' AND `Variant` LIKE '".$variant."' ORDER BY `pms_id` ASC";
    $result = $this-&gt;db-&gt;query($query);
    return $result-&gt;result();
  
    print_r($result-&gt;result());
  }
  </code></pre>
  
  <p>View:</p>
  
  <pre><code>&lt;select id="fuel" onchange="getKm()" &gt;
    &lt;option value="na"&gt;Fuel&lt;/option&gt;
  &lt;/select&gt;
  
  &lt;script&gt;
    function getFuel() {  
      var getVariant = $('#variant').val();
      var car_model = $('#car_model').val();
      console.log("this is inside get Fuel");
  
      console.log(car_model);
      console.log(getVariant);
  
      $.ajax({
        url: "&lt;?php echo base_url() ?&gt;pms1/getFuel/"+car_model+"/"+getVariant, 
        dataType: "html",
        success: function(result) {
          $('#fuel').html('&lt;option&gt;SELECT&lt;/option&gt;');
          $.each(JSON.parse(result), function() {            
            $('#fuel').append(result);
          });  
        }
      });
    }
  &lt;/script&gt;
  </code></pre>
  
  <p>Controller:</p>
  
  <pre><code>public function getFuel($modelid, $variant) 
  {
      $car_model = $modelid;
      $getVariant = $variant;
  
      $this-&gt;load-&gt;model('M_address');
      $fuel = $this-&gt;M_address-&gt;getFuel($modelid,$variant);
  
      $fuel_list = array();
      foreach ($fuel as $fuels) 
      {
        array_push($fuel_list, $fuels-&gt;fuel);
      }
      $fuel_list = array_unique($fuel_list);
      // echo '&lt;option value="na"&gt;Fuel&lt;/option&gt;';
      foreach ($fuel_list as $fuel) 
      {   
        $ts = explode('/', $fuel);
        $ss = count($ts);
        foreach($ts as $tt)
        {
          echo '&lt;option value="' . $fuel . '"&gt;' . $tt . '&lt;/option&gt;';
          //I've tries adding json_encode on the above line.
        }
      }                      
    }
  </code></pre>