title: Using Ajax to show data in combobox
body: <p>I am trying to show the data from my database in my combobox with ajax but then I run the script my combobox stays empty.</p>
  
  <p>Here is my combobox</p>
  
  <pre><code>&lt;select id="name" name="name"&gt;
      &lt;option value= ""&gt;&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>
  
  <p>With the following PHP script I am trying to select the data from my database:</p>
  
  <pre><code>&lt;?php    
  $servername = "localhost";
  $username = "root";
  $password = "pass";
  $dbname = "db";
  
  $conn = new mysqli($servername, $username, $password, $dbname) ;
  if ($conn-&gt;connect_error) {
      die('Connection failed: ' . $conn-&gt;connect_error) ;
  }else {
  
      $query = 'SELECT * FROM scu_stock';    
      $res = mysqli_query($conn, $query) ;
    if (mysqli_num_rows($res) &gt; 0) {
       $result = mysqli_fetch_assoc($res) ;
      echo $result['name'];
    }else{
       $result = mysqli_fetch_assoc($res) ;
      echo "error";
    }    
  } 
  ?&gt;
  </code></pre>
  
  <p>The following code should enter the data in the combobox:</p>
  
  <pre><code>&lt;script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"&gt;&lt;/script&gt;
  &lt;script&gt; 
    function getCode() { 
      console.log("getCode before ajax", jQuery('#name').val());
      jQuery.ajax({ 
        url: './get/get1.php', 
        method: 'POST', 
        data: {'id' : jQuery('#name').val()},
        success: function(response){ 
          console.log("getCode after ajax", jQuery('#name').val());
          jQuery('#name').val(response);
        }, 
        error: function (request, status, error) { 
          alert(request.responseText); 
        }, 
      });                 
    } 
  &lt;/script&gt;
  </code></pre>
  
  <p>The script returns empty and I cant see any changes in the combobox. Does someone know what is wrong with the script?</p>
  
  <p><strong>Update 1:</strong></p>
  
  <p>When I change the combobox to a textbox I can see that the textbox is filled with data. I cant get the data that is returned from the database in the combobox. Does someone know a solution for this problem?</p>
  
  <p>This works:</p>
  
  <pre><code>&lt;input type="text" id="name" name="name" /&gt;
  </code></pre>
  
  <p>This is not working:</p>
  
  <pre><code>&lt;select id="name" name="name"&gt;
      &lt;option value= ""&gt;&lt;/option&gt;
  &lt;/select&gt;
  </code></pre>