Php 将值和MySQL检索到的值一起作为JavaScript中的隐藏值传递给AJAX函数
我对php、ajax表单有疑问。。 让我解释一下预期的情况Php 将值和MySQL检索到的值一起作为JavaScript中的隐藏值传递给AJAX函数,php,javascript,mysql,html,jquery,Php,Javascript,Mysql,Html,Jquery,我对php、ajax表单有疑问。。 让我解释一下预期的情况 我已经使用产品id更新了购物车中的产品数量,这是关键 我使用的是下拉列表,一旦更改它就会调用ajax函数,并将值(即is quantity as this.value)与从mysql数据库检索到的产品id一起传递 在javascript函数中,它通过ajax传递两个值,在php中,它获取值并更新相应产品的数量 成功后,它必须在不重新加载整个页面或表单的情况下返回表单上的更新值 4.这个问题我纠结了一个星期,找不到答案。。请帮帮我 让你知
<select name="update" onchange="updatequantity(this.value,<?php echo $row['products_id']; ?>)" >
这是在使用dojo
在head标签中添加以下内容
<script src="http://ajax.googleapis.com/ajax/libs/dojo/1.7.2/dojo/dojo.js"></script>
<script type="text/javascript">
function updatequantity(input, id)
dojo.xhrPost({
url: "updatequantity.php",
content: {
id: id,
quantity: input.value
},
load: function(result) {
result //this variable will hold the quantity
}
});
</script>
函数updatequantity(输入,id)
dojo.xhrPost({
url:“updatequantity.php”,
内容:{
id:id,
数量:输入值
},
加载:函数(结果){
结果//此变量将保存数量
}
});
在服务器上:updatequantity.php
<?php
$id = $_POST['id'];
$quantity = $_POST['quantity'];
//some sql query like "update cart_items set quantity=".$quantity." where id=".$id.";"
echo $quantity;
您可能会在updatequantity
函数中有一个或多个调用,将这些参数发送到PHP,并在其回调中显示/附加响应文本到文档中,在野外有数千个优秀的jquery ajax指南(jquery是小菜一碟)。