我正在使用codeigniter开发购物车。当我通过ajax发送数据给控制器时,它不起作用。这里是我的Ajax代码我使用 您可以检查我的演示ebsite在这下面的链接通过ajax向控制器发送数据不起作用
$(".add_to_cart").click(function(event) {
var id=$(this).data('id');
var qty=$("#item_"+id).val();
$.ajax({
type: 'POST',
url: '<?php echo base_url("ajax_controller/add_to_cart/'+id+'/'+qty+'")?>',
data: { id:id },
success:function(response){
$("#total_items").html(response);
$(".view_cart").click();
}
});
<input type="number" value="1" id="item_<?php echo $row->product_id; ?>" />
<a id="edit_product" data-id="<?php echo $row->product_id; ?>" class="add_to_cart">Add to Cart</a>
当我警报(数量)和警报(id)我得到结果。 但我没有在我的ajax_controller中获取值。
这是我的控制器
public function add_to_cart($pid,$qty)
\t {
\t \t $this->load->model('product_model');
\t \t $query=$this->product_model->get_product($pid);
\t \t
\t \t foreach ($query->result() as $row)
\t \t {
\t \t $name=$row->product_name;
\t \t $price=$row->price;
\t \t $img=$row->img_name;
\t \t }
\t \t
\t \t
\t \t \t $data = array(
'id' => $pid,
'qty' => $qty,
'price' => $price,
'name' => $name,
'options' => array('Status' => 'New')
);
\t \t \t $this->cart->insert($data);
\t \t \t
\t \t \t echo count($this->cart->contents());
\t }
请分享您的控制器代码'ajax_controller/add_to_cart' –
请分享你的'ajax_controller'控制器代码@Yadhu巴布 –
我的问题是,我需要GRT该产品ID和$数量在我的Ajax控制器 –