gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 22:51:52 25 4
gpt4 key购买 nike

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);
}
});

});
});

pricegetter.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},

关于javascript - 更改单选按钮的事件以从 mysql 表中获取值,但不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27957206/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com