Ajax通过php获取价格

Hi the code below works and what the code does it for category is just a drop down for a user to select but for the drop down for the Length when the user select the length it should make an ajax to the database and then whatever the price for that length the user select from the dropdown should show when the price is.

SELECT price FROM product WHERE
 category=:dropdownval1 AND 
 type=:dropdownval2 AND prodID=:id

so far all I know is that the ajax should run the query above but I have no idea how to get ajax to run this query, I have try 2 different codes so far but none of them is working. Can someone point me in the right direct.

I know it the ajax to GET the price via php, and then in the callback you change the price with jquery

<form>
             <tr>
<td width="160">Price:</td>
<?php
    dbconnect(); 
    $stmt2 = $conn->prepare("SELECT Length, price FROM Product WHERE ProdID=:id LIMIT 1");
    $stmt2->bindParam('id',$id);
    $stmt2->execute();
    $i = 0;
    foreach ($stmt2->fetchAll(PDO::FETCH_ASSOC) as $row2) {
        if ($i == 0) {  
            echo '<td>'.$row2['price'].'</td>';
        }
    }
?>

<tr>    
        <td>Category</td>   
            <td>
            <select name="Category">
        <?php
        dbconnect(); 
        $stmt = $conn->prepare("SELECT Category FROM Product WHERE ProdID=:id GROUP BY Category");
        $stmt->bindParam('id',$id);
        $stmt->execute();
        $i = 0;
        foreach ($stmt->fetchAll(PDO::FETCH_ASSOC) as $row ) {
        if ($i == 0) {
        $dropdownval1 = $row['Category']; 
        echo '<option SELECTED value="'.$row['Category'].'">'.$row['Category'].'</option>';
        }
        else {
        echo '<option value="'.$row['Category'].'">'.$row['Category'].'</option>';
        }
        $i++;
        }
        ?>

        </select>
        </td>
        </tr>

             <tr>
            <td width="160">Length:</td>
                                <td>
            <select name="length">
        <?php
        dbconnect(); 
        $stmt3 = $conn->prepare("SELECT Length, Price FROM Product WHERE ProdID=:id AND Category=:dropdownval1");  
        $stmt3->bindParam('id',$id); 
        $stmt3->bindParam('dropdownval1',$dropdownval1 );
        $stmt3->execute();
        $i = 0;
        foreach ($stmt3->fetchAll(PDO::FETCH_ASSOC) as $row3 ) {
        if ($i == 0) {
        echo '<option SELECTED value="'.$row3['Hair_Length'].'">'.$row3['Hair_Length'].'</option>';
        }
        else {
        echo '<option value="'.$row3['Hair_Length'].'">'.$row3['Hair_Length'].'</option>';
        }
        $i++;
        }
        ?>
        </select>
        </td>    
    </form>

Try this one make sure you have included jquery and then onchange of length dropdown make an ajax request to your php file where your are fetching price

  <select name="Category" class="Category">
 <select name="Category" onchange="getprice(this.value)">
 function getprice(length) {
          if (length== "") {

          } else {

              $.ajax({
                  type:'post',
                  url:'your.php',
                  data:{length:length,category:$(".Category option:selected").val()},
                  success:function (data) {
                      $(yourhtmlelement).html(data);

                  }
              })
          }
      }

Hope this makes sense