更改单选按钮的事件以从MySQL表中获取值,不起作用


change event of a radio button to get a value from mysql table, not working

jQuery(document).ready(function(){    
$("#qty1").change(function(e) {
    var quantity = $(this).val();
        $.ajax({
            url: 'pricegetter.php',
            type: 'POST',
            data: {quantity: quantity},
            success: function(result) {
                $('#price').val(result);
            }
        });
});
});

价格获取者的代码.php

include("config.php");
$q = mysql_query("select rate FROM products WHERE qty= '".$_POST['quantity']."'");
if(mysql_num_rows($q)<=0) echo "none";
else{
$r = mysql_fetch_array($q);
echo $r["rate"];
}

用于触发事件的单选按钮

<input type='radio' value='".$row['qty']."' name='qty1' id='qty1'/> ".$row['qty'] ."  ".$row['unit'] />

我的值由文本字段存储。

<input type='text' name='price' id='price'/>

上面的这些代码没有按预期完美运行。 请帮我找到错误。我的 PHP 代码单独运行良好,没有语法或字段名称错误。

我的代码的目的是,当我选择 qty1 单选按钮时,它将为您提供与特定产品的数量相关的价格。[附言我正处于代码的第一步。我不知道如何使用jquery发送两个值作为发布操作,所以我只发送数量,但它没有给我价格。然后,我将尝试通过jquery提供productID。

您可以使用逗号分隔值发送多个数据,就像在 ajax 中一样

data: {quantity: quantity,price:price},