title: How to pass select option array from ajax to codeigniter view?
body: <p>I found the best answer <a href="https://stackoverflow.com/questions/170986/what-is-the-best-way-to-add-options-to-a-select-from-an-array-with-jquery/27058731?noredirect=1#comment42649791_27058731">here</a>, but when I implemented it in my code, here's what happen to the dropdown select option:</p>
  
  <p>"<br/>
  1<br/>
  "<br/>
  :<br/>
  "<br/>
  t<br/>
  e<br/>
  s<br/>
  t<br/>
  1<br/>
  "<br/>
  ,<br/>
  (and so on).</p>
  
  <p>What's wrong with it?</p>
  
  <p>The ajax code in view:</p>
  
  <pre><code>$.ajax({
  type: "POST",
  url: "&lt;?php echo base_url();?&gt;/index.php/main/get_location",
  data: data_loc,
  success: function(locs)
  {
      //alert(locs); when I do this, the alert shows: {"1": "test 1", "2": "test 2"}.
      $('#location').empty();
      $('#location').show();
      $.each(locs,function(id,location_description){
          $('#location').append($("&lt;option&gt;&lt;/option&gt;").attr("value",id).text(location_description));
      });
  }
  </code></pre>
  
  <p>});</p>
  
  <p>In controller:</p>
  
  <pre><code>public function get_location()
  {
      $this-&gt;load-&gt;model("xms/model_db"); 
      echo json_encode($this-&gt;model_db-&gt;get_location_by_group($_POST['location_gr']));
  }
  </code></pre>