简体   繁体   English

当我在代码中单击添加到购物车时,我得到的值相同。 这是PHP中的ajax响应

[英]I am getting the same value when I click on add to cart in my code. It's an ajax response in php

This is the script. 这是脚本。 When I click on add to cart, it picks only single value from the below code in php file. 当我单击添加到购物车时,它从php文件中的以下代码中仅选择单个值。 But when I checked my response it show both values and on my page I am getting all values from database but when I click on add to cart, I am getting same value every time: 但是,当我检查响应时,它同时显示了值和页面上的值,我从数据库中获取了所有值,但是当我单击“添加到购物车”时,每次都得到相同的值:

<script>
$(document).ready(function() {
    alert("Page loaded");
    jQuery.ajax({
        url: "<?php echo $BASE_URL; ?>daily_menu_dishes.php",
        dataType : "html",
        data:'store_id='+$("#store_id").val()+'&store_name='+$("#store_name").val(),
        type: "POST",
        success:function(data){ 
            //alert(data);
            $("#dily-meal-product-container").html(data);
            //$("#calender_day").html(data);
            //$("#loaderIcon1").hide();
        },
        error:function (){}
    });
});
</script>  

And this is in php: 这是在PHP中:

while($row=mysql_fetch_assoc($result)){
    $html=' <div class="col-xs-6 col-sm-6 col-md-4  first_col" style="width:23.333%">                   
    <div class="thumbnail">
        <img class="img-responsive" src="http://teq-staging.com/maswad-phase2/storeadmin/uploads/dish_images'.'/'.$row['image'].' "  width="250px;min-height:0px ! important;">
        <div class="caption">
            <div class="user">
                <a style="cursor:pointer"> <img class="img-responsive" src="http://app.msdev.in/uploads/cooks/70X70/default-70X70.jpg" alt="Beenu"></a>
            </div>
            <div class="body-content" style="width:175px;">
                <h2> <a>'.$row["dish"].'</a></h2>
                <div class="add-items" style="width:100px;float:right">
                    <span id="add-item-mini-5" class="add-to-cart active" onclick="addToCart();">ADD to Cart</span>
                </div>
                <div style="font-size:20px;width:100px;float:left;mrgin-top:-55px;">
                    <i class="fa fa-inr"></i> '.$row["sell_price"].'
                    <input type="hidden" name="sell_price" id="sell_price" value="'.$row["sell_price"].'">
                    <input type="hidden" name="dish_name" id="dish_name" value="'.$row["dish"].'">
                    <input type="hidden" name="dish_id" id="dish_id" value="'.$row["id"].'">
                </div>
            </div>
            <div class="veg-symbol"><i class="veg-circle"></i></div>
                <!-- <ul class="last-tab">
                    <li id="favourite-5" onclick="addToFavorite(5, this)">
                        <i class="fa fa-heart"></i>Add to Favourite</li>
                    <li onclick="productDetailModal(5)"><i class="open-eye"></i>Know More</li>
                </ul>  -->
            </div>
        </div>
    </div>
</div>';
    echo $html;
}

Your requests are cached. 您的请求已缓存。 Set cache: false since it is true by default . 设置cache: false因为默认情况下为true

jQuery.ajax({
    url: "<?php echo $BASE_URL; ?>daily_menu_dishes.php",
    cache: false,
    dataType : "html",
    data:'store_id='+$("#store_id").val() + '&store_name=' + $("#store_name").val(),
    type: "POST",
    success:function(data){ 
        //alert(data);
        $("#dily-meal-product-container").html(data);
        //$("#calender_day").html(data);
        //$("#loaderIcon1").hide();
    },
    error:function (){}
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以从javascript函数获取网址。 我需要使用php代码将相同的URL存储在我的数据库中。 - I am able to get the url from javascript function. I need same url to be stored in my database using php code. 使用ajax从php发送和返回值时,为什么会得到javascript和html代码? - Why am i getting javascript and html code when using ajax to send and return value from php? 我的代码有什么问题。 我想在现有商品的购物车中添加新商品 - Whats wrong with my code. I want to add new item in the cart with the existing item 我在cart.php页面中遇到错误 - I am getting error in my cart.php page 我正在尝试通过php代码更新记录。 但是我的代码有麻烦 - I am trying to update records by php code. but having trouble in my code 我在 php 代码中遇到错误。 试图访问 wamp 服务器上 php 中的输入值。 它作为未定义的变量给出错误,但我的代码是正确的 - i'm getting error in php code. trying to access input value in php on wamp server. it gives error as undefined variable but my code is correct 为什么我在下面的代码中只获得数组“行”中的第一行值。 我需要与查询对应的所有值 - why am i only getting the first row value in array "row" in the below code. i need all the values corresponding to the query 当我使用 wsdl 和端点 url 执行我的 curl php 请求时得到空白响应 - Getting Blank response when i am executing my curl php with request with wsdl and endpoint url 我需要帮助来查找我的代码有什么问题。 这是来自Larry Ullman的Web上的PHP书籍 - I need help finding what is wrong with my code. This is from Larry Ullman's Book PHP for the Web 当我点击添加到购物车按钮时会发生什么我在 laravel 中遇到了一些错误? - what happens when i click add to cart button i am facing some error in laravel?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM