Php 如何使用Jquery数字微调器更新DB中的数量?

Php 如何使用Jquery数字微调器更新DB中的数量?,php,jquery,symfony,Php,Jquery,Symfony,我不熟悉JQuery/JavaScript/Ajax以及Symfony2和PHP 我正在构建一个简单的购物车,我希望用户能够使用JQuery微调器()控制他们在购物车中添加的产品数量 作为新手,我真的需要一些帮助来做这件事 我所有的尝试都失败了,我只是在挣扎 HTML/细枝: <tbody> {% for key, product in quantity %} <tr>

我不熟悉JQuery/JavaScript/Ajax以及Symfony2和PHP

我正在构建一个简单的购物车,我希望用户能够使用JQuery微调器()控制他们在购物车中添加的产品数量

作为新手,我真的需要一些帮助来做这件事

我所有的尝试都失败了,我只是在挣扎

HTML/细枝:

        <tbody>
        {% for key, product in quantity %}  
                <tr>
                    {{ dump(key) }}
                    <td>{{ product.product }}</td> <!--Product--> 
                    <td>
                        <input class="spinner" value="{{ product.quantity }}" style="width:30px">
                    </td> <!--Quantity-->
                    <td>${{ product.product.price|default('') }}</td> <!--Price-->   
                    <td>
                        <a href="{{ path('product_remove', {'id': key }) }}">
                            <button name="REMOVE" type="button" class="btn btn-danger" id="removeButton">
                                <span class="glyphicon glyphicon-remove" aria-hidden="true"></span>
                            </button>
                        </a>
                    </td><!--Remove--> 
                </tr>
            {% endfor %}      
        </tbody>
    </table> <!--top table-->
<script type="text/javascript">
    $(".spinner").spinner();
</script>

使用jQuery处理微调器上的
change
事件。更新后,向数据库发出更新请求

用您的url替换下面的
url

$('input.spinner').on('change', function(){
    var $this = $(this);
    $.ajax({
        url: '/path/to/update/my/product/quantity',
        method: 'POST',
        data : {
            quantity: $this.val()
        }
    }).done(function(resp){
        console.log('success', resp);
    }).error(function(err){
        console.log('error', resp);
    });
});
手动处理
$\u POST['quantity']
中的产品数量,并相应地更新
购物车


在Symphony控制器内部处理此问题的逻辑超出了范围,因为它太宽,并且没有足够的信息来给出明确的方向

对不起,如果这是一个愚蠢的问题,但我如何找到/知道我的更新数量的url?这是我浏览器中的url吗?@user6104636是-无论您选择哪个页面。您可以自己创建路由来处理数据,因此无论您需要它到哪里都可以。
$('input.spinner').on('change', function(){
    var $this = $(this);
    $.ajax({
        url: '/path/to/update/my/product/quantity',
        method: 'POST',
        data : {
            quantity: $this.val()
        }
    }).done(function(resp){
        console.log('success', resp);
    }).error(function(err){
        console.log('error', resp);
    });
});