我是代码点火器的新手。在这里,我使用购物车进行产品结账。当我添加产品到购物车时,它正在为前三种产品工作,在添加任何产品后视为第四种产品。如果任何产品在三种产品之后加入购物车,它将取代现有的第四种产品。但只有前三个产品显示在购物车上,第四个产品没有显示,我也不能在购物车上添加超过四个产品,我使用jquery ajax进行购物车更新
jquery ajax代码
$('.addcart').click(function(){
var proid=$(this).attr('id');
$.post('<?php echo base_url()?>productajax',{typ:'addtocart',proid:proid},function(data){
})
return false;
})
product add to cart code
$proid=$this->input->post('proid');
$this->db->where('pro_id',$proid);
$data=$this->db->get('product')->result();
foreach ($data as $pro)
{
$proname=$pro->pro_name;
$price=$pro->s1price;
$proimg=$pro->image_name;
$nwt=$pro->case_netweight;
$gwt=$pro->case_grossweight;
$cbm=$pro->cbm;
}
$propriceinr =round($price + round(($price * $this->session->userdata('user_margin'))/100,2));
$dat = array(
'id' => $proid,
'qty' => 1,
'price' => $propriceinr,
'name' => $proname,
'options' => array('cbm' => $cbm, 'nwt' => $nwt,'gwt'=>$gwt,'image' => $proimg ,'price'=>$price,)
);
$this->cart->insert($dat);
config.php
$config['sess_cookie_name'] = 'ci_session';
$config['sess_expiration'] = 7200;
$config['sess_expire_on_close'] = FALSE;
$config['sess_encrypt_cookie'] = FALSE;
$config['sess_use_database'] = FALSE;
$config['sess_table_name'] = 'ci_sessions';
$config['sess_match_ip'] = FALSE;
$config['sess_match_useragent'] = TRUE;
$config['sess_time_to_update'] = 300;
$config['csrf_protection'] = FALSE;
$config['csrf_token_name'] = 'csrf_test_name';
$config['csrf_cookie_name'] = 'csrf_cookie_name';
$config['csrf_expire'] = 7200;
我不知道产品购物车为什么不插入三个产品后更新。给我这个问题的指导任何人。谢谢提前
答案 0 :(得分:2)
请设置
$config['sess_use_database'] = FALSE;
到$config['sess_use_database'] = TRUE;
中的config.php
。
目前,您的产品详细信息保存在 Cookie 中,其最大限制为 4kb 。
启用$config['sess_use_database'] = TRUE;
。
此功能允许您在数据库表中插入信息,即:
$config['sess_table_name'] = 'ci_sessions';
。
希望这对你有用
如果你没有ci_sessions
表,那么查询:
CREATE TABLE `ci_sessions` (
`session_id` varchar(40) NOT NULL DEFAULT '0',
`ip_address` varchar(16) NOT NULL DEFAULT '0',
`user_agent` varchar(50) NOT NULL,
`last_activity` int(10) unsigned NOT NULL DEFAULT '0',
`user_data` text NOT NULL,
PRIMARY KEY (`session_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
答案 1 :(得分:0)
尝试在application / config / config.php中禁用csrf保护
$config['csrf_protection'] = FALSE;
然后,如果ajax调用开始工作,再次启用它并将ci_csrf_token变量添加到ajax调用。