javascript - give a value to input when move then save it by ajax - php / jquery -php -
i want create shopping cart , i'm finish. use ajax dynamic search , ajax add cart , use jquery refresh specific div when click face problem.my problem quantity problem. use session store value //this session update code
$con = mysqli_connect("localhost", "root" , "","atest"); session_start(); require("functions.php"); cart_session(); $id=$_post['id']; //echo $arr['cart']; if(isset($_session[$arr["cart"]][$id])){ $_session[$arr["cart"]][$id][$arr["quantity"]]++; //redirect("http://localhost/my/work/sellingcart/index.php",true); }else{ $sql_s="select * product_1 p_id={$id}"; //echo $sql_s; $query_s=mysqli_query($con,$sql_s); if(mysqli_num_rows($query_s)!=0){ $row_s=mysqli_fetch_array($query_s); $_session[$arr['cart']][$row_s["p_id"]]=array( "{$arr["quantity"]}" => 1 ); //redirect("http://localhost/my/work/sellingcart/index.php",true); }else{ $message="this product id it's invalid!"; } }
//use ajax update cart
<script> $("#link").click(function(e) { e.preventdefault(); var id = $("#id").val(); var datastring = 'id='+id; $('#loading-image').show(); $(".form :input").attr("disabled", true); $('#remove_cart').hide(); $('#link').hide(); $(".container").css({"opacity":".3"}); $(".form :input").attr("disabled", true); $('#remove_cart').hide(); $('#link').hide(); $.ajax({ type:'post', data:datastring, url:'add_cart.php', success:function(data) { $('#availability').html(data); }, complete: function(){ $('#loading-image').hide(); $(".form :input").attr("disabled", false); $('#remove_cart').show(); $('#link').show(); $(".container").css({"opacity":"1"}); } }); //$("#chat").load(location.href + " #chat"); //$("#chat").load(location.href+" #chat>*",""); }); </script>
here image , red mark problem.
i want update cart when give value , move update session ajax , php.
is there help? don't want user can update there quantity every cart item singly. want dynamic give quantity number , move save ajax.
assign onchange event quantity input boxes:
$('input[name=quantitybox]').change(function() { ... });
in function() above, add ajax post request containing like
var quantity = $('input[name=quantitybox]').val(); // var id = something; $.ajax({ type:'post', data:"productid=" + id + "&updatequantity=" + quantity, url:'add_cart.php', success:function(data) { $('#availability').html(data); }, complete: function(){ // want on successful update of request } });
in php function above, check whether product exists in user's cart. @ point, change quantity.
if(isset($_session[$arr["cart"]][$id])){ $quantity = $_post['updatequantity']; $id = $_post['productid']; $_session[$arr["cart"]][$id][$arr["quantity"]] = $quantity; }
Comments
Post a Comment