将值与MySQL一起传递,将检索到的值作为JavaScript中的隐藏值传递给AJAX函数


Passing value along with MySQL retrieved value as hidden value in JavaScript to AJAX function

我对php,ajax形式有疑问。让我解释一下预期的场景...

  1. 我使用产品ID是关键更新了购物车中的产品数量。

  2. 我正在使用下拉列表,onchange 它调用 ajax 函数并将值(即数量为 this.value)以及从 mysql DB 检索的产品 id 一起传递。

  3. javascript函数中,它通过ajax传递两个值,在php中,它获取值并更新相应products_id的数量。

  4. 成功后,它必须返回表单上的更新值,而无需重新加载整个页面或表单...

把这个问题堆积了一个星期,我无法得到答案。.请帮助我..

让你知道我是如何调用javascript函数的,

<select name="update" onchange="updatequantity(this.value,<?php echo $row['products_id']; ?>)" >  

但是这个调用函数无法将值发送到 ajax...

这是

使用道场。

在头标签中添加以下内容

<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>

在服务器上:更新数量.php

<?php
$id = $_POST['id'];
$quantity = $_POST['quantity'];
//some sql query like "update cart_items set quantity=".$quantity." where id=".$id.";"
echo $quantity;

这个解决方案非常被黑客攻击,并且受到许多攻击的尊重,例如SQL注入和精明的javascripter。