JQUERY post 方法总是返回到第一个表

我开始学习 jquery ajax,所以我将我的网站修改为 ajax,但在传递数据时仍然出错,成功访问但总是返回第一列


这是我的调用值的代码:


while ($r=mysql_fetch_array($query)) {

<a id="tambahkan-cart"  value='.$r[id_product].' data-toggle="modal" href="#modal-one"  class="btn btn-default add-to-cart"><i class="fa fa-shopping-cart"></i>Add to cart</a>

}

这是我点击调用的代码


$("#tambahkan-cart").click(function() {

        event.preventDefault();

        

                var id_product = $(this).attr("value");

                $.ajax({

                    url: 'tambah-cart.php',

                    type: 'POST',

                    data: {

                        id_product: id_product

                    },

                    success: function(data) {

                        $("#modal-body").html(data);

                    }

                });

            });


这里 tambah-cart.php.. 我需要在这里传递数据,但它返回值='1',.. 我想动态传递数据



$idp=$_POST['id_product'];

$q=mysql_query("SELECT * from `product` WHERE id_product='$idp' ");


如果你告诉我哪里错了,我将不胜感激......我在点击时为不同的 id_product 使用了不同的值,但它返回到第一列,,,..谢谢


千巷猫影
浏览 80回答 2
2回答

梵蒂冈之花

我想我也会提请您注意这段代码。跟事件有关改变这个$("#tambahkan-cart").click(function() {&nbsp; &nbsp;event.preventDefault();&nbsp; &nbsp;var id_product = $(this).attr("value");&nbsp; &nbsp;$.ajax({&nbsp; &nbsp; &nbsp; url: 'tambah-cart.php',&nbsp; &nbsp; &nbsp; type: 'POST',&nbsp; &nbsp; &nbsp; data: {&nbsp; &nbsp; &nbsp; id_product: id_product&nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; success: function(data) {&nbsp; &nbsp; &nbsp; &nbsp; $("#modal-body").html(data);&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;});&nbsp;});到$("#tambahkan-cart").click(function(event) {&nbsp; &nbsp;event.preventDefault();&nbsp; &nbsp;var id_product = $(this).attr("value");&nbsp; &nbsp;$.ajax({&nbsp; &nbsp; &nbsp; url: 'tambah-cart.php',&nbsp; &nbsp; &nbsp; type: 'POST',&nbsp; &nbsp; &nbsp; data: {&nbsp; &nbsp; &nbsp; id_product: id_product&nbsp; &nbsp; &nbsp; },&nbsp; &nbsp; &nbsp; success: function(data) {&nbsp; &nbsp; &nbsp; &nbsp; $("#modal-body").html(data);&nbsp; &nbsp; &nbsp; }&nbsp; &nbsp;});&nbsp;});

牧羊人nacy

改变这个$q&nbsp;=&nbsp;mysql_query("SELECT&nbsp;*&nbsp;from&nbsp;`product`&nbsp;WHERE&nbsp;id_product='$idp'&nbsp;");到$q&nbsp;=&nbsp;mysqli_query("SELECT&nbsp;*&nbsp;from&nbsp;`product`&nbsp;WHERE&nbsp;id_product='$idp'&nbsp;");
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript