Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/82.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 由多个按钮激活的jqueryajax_Javascript_Jquery_Mysql_Ajax - Fatal编程技术网

Javascript 由多个按钮激活的jqueryajax

Javascript 由多个按钮激活的jqueryajax,javascript,jquery,mysql,ajax,Javascript,Jquery,Mysql,Ajax,我从mysql中提取数据并制作4个按钮;然后尝试使用jquery/ajax调用事件。只有第一个有效,其他3个无效 以下是查询: <div class="row"> <? $query="SELECT * from product_bid order by RAND() LIMIT 4"; $result=mysql_query($query); while($row=mysql_fetc

我从mysql中提取数据并制作4个按钮;然后尝试使用jquery/ajax调用事件。只有第一个有效,其他3个无效

以下是查询:

<div class="row">
            <?  $query="SELECT * from product_bid order by RAND() LIMIT 4"; 
                $result=mysql_query($query);
                while($row=mysql_fetch_array($result))
                { ?>
                <div class="col-sm-3">
                    <div class="product">
                         <div class="title"><strong>Iphone 16GB</strong></span></div>
                         <img class="img-responsive" src="">
                         <small>ราคา <?=$row['price']; ?> บาท</small><hr>
                            <span class="countdown">00:23:32</span> <br>
                            <span class="price" id="price"><?= $row['total_bids']; ?> บาท</span> <br>
                            <span class="user">user</span> <br>
                            <input type="hidden" id="productid" name="id" value="<?= $productid=$row['id']; ?>">
                            <span class="bid btn btn-button btn-success btn-md" value="Bid">Bid</span>
                        </div>
                </div>

            <?  }

            ?>
      </div>

Iphone 16GB
ราคา  บาท
00:23:32
บาท
用户

页面上不能有多个id相同的元素。请将productid更改为类,或者以另一种方式更改它,使每个元素的id都是唯一的。价格也一样。如果你那样做的话

$(".bid").click(function () {
    buttonClick($(this));
});

function buttonClick($bid) {
    var $parent = $bid.parent();
    var productid = $parent.find('.productid').val();
    var $price = $parent.find('.price');

    $.ajax({
        type: "GET",
        url: "bid.php",
        data: 'id='+ productid,

        //  success: function(msg){
        //      $price.html(msg);
        //  }

    }); // Ajax Call
}
$(".bid").click(function () {
    buttonClick($(this));
});

function buttonClick($bid) {
    var $parent = $bid.parent();
    var productid = $parent.find('.productid').val();
    var $price = $parent.find('.price');

    $.ajax({
        type: "GET",
        url: "bid.php",
        data: 'id='+ productid,

        //  success: function(msg){
        //      $price.html(msg);
        //  }

    }); // Ajax Call
}