jquery - update shopping cart using ajax and laravel -
im using package crinsane/laravelshoppingcart
and want update cart items ajax, im using laravel 5.4 , jquery. cant update cart ajax.
if use without jquery have pass id of product this:
/cart/add-item/{id}
this code:
the route: web.php
route::get('/cart/add-item/{id}', 'cartcontroller@additem')->name('cart.additem');
the controller: cartcontroller.php
public function additem($id){ $productos = db::connection('oracle_db')->select("select id,description, price inv.pwv_articulos id = '$id'"); foreach($products $product){ $products_id = $product->id; $products_descripcion = $product->description; $products_price = $product->precio; } cart::add($products_id, $products_description , 1 , $products_price, ['size'=> 'medium']); return back(); }
my js jquery:
formdata = $('#color_black').serializearray(); var value_color = formdata[0]['value']; //alert(value_color); $.ajax({ type: "get", url: "cart/add-item/".value_color, success: function(response){ console.log("{{cart::total()}}"); } });
your issue in line:
url: "cart/add-item/".value_color,
in order concatenate strings in javascript need use plus sign:
url: "cart/add-item/" + value_color,
Comments
Post a Comment