Search code examples
javascriptjqueryajaxhtmljquery-ajaxq

How to add option to select form as received from AJAX request in PHP


What is method to adding option to select box data received by AJAX

HTML:

<select id="options"></select>

jQuery:

$.ajax({
  type: "POST",
  url: "ajax/addCustDetail.php",
  data: {customerId},
  cache: false,
  success: function(html)
  {
    $("#options").html(html);
  } 
});

Solution

  • PHP Side Code :

    $cid=$_POST['cid'];
    $query="SELECT * from customer_shipping_address WHERE STransNo=$cid";        
    $result1 = mysqli_query($con, $query);
    while ($row = mysqli_fetch_array($result1, MYSQLI_ASSOC)) {
        echo "<option value=".$row['TransSlNo'].">".$row['ShipName']."</option>" ;   
    }