购物车->插入();不在 CI 工作
cart->insert(); not working in CI
我检查了所有堆栈站点,google 也检查了它。但我找不到合适的解决方案。
有人对此有想法吗?
Question is data not get insert to cart. I echo data inside controller data retrieving to controller well.
But not get inserting to cart??
控制器
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cart extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('session');
$this->load->model('Product_Model');
$this->load->library('cart');
}
public function index()
{
}
public function insert_cart()
{
$data = array(
'id' => $this->input->post('id'),
'qty' => $this->input->post('qty'),
'price' => $this->input->post('price'),
'name' => $this->input->post('head'),
);
$cartdata = $this->cart->insert($data);
if(!empty($cartdata)){
print_r($cartdata);
}else{
echo "no data";
}
// $count = $this->cart->contents();
// print_r($count) ;
die();
}
}
正在查看ajex数据发送。
<script>
$(function(){
$( "#submit" ).click(function(event) {
event.preventDefault();
var head= $("#head").text();
var price= $("#price_value").val();
var pid= $("#pid").text();
var qty= $("#qty").val();
// alert(price);
$.ajax({
type:"post",
url: "<?php echo base_url(); ?>index.php/cart/insert_cart",
data:{
head:head, price:price,pid:pid,qty:qty
}
});
});
});
</script>
问题出在您通过 pid
的 ajax 请求中的 id
head:head, price:price,pid:pid,qty:qty
^^^^^^^^
所以你收到 pid
而不是 id
'id' => $this->input->post('pid'),// here receive pid not id
我检查了所有堆栈站点,google 也检查了它。但我找不到合适的解决方案。
有人对此有想法吗?
Question is data not get insert to cart. I echo data inside controller data retrieving to controller well. But not get inserting to cart??
控制器
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Cart extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->library('session');
$this->load->model('Product_Model');
$this->load->library('cart');
}
public function index()
{
}
public function insert_cart()
{
$data = array(
'id' => $this->input->post('id'),
'qty' => $this->input->post('qty'),
'price' => $this->input->post('price'),
'name' => $this->input->post('head'),
);
$cartdata = $this->cart->insert($data);
if(!empty($cartdata)){
print_r($cartdata);
}else{
echo "no data";
}
// $count = $this->cart->contents();
// print_r($count) ;
die();
}
}
正在查看ajex数据发送。
<script>
$(function(){
$( "#submit" ).click(function(event) {
event.preventDefault();
var head= $("#head").text();
var price= $("#price_value").val();
var pid= $("#pid").text();
var qty= $("#qty").val();
// alert(price);
$.ajax({
type:"post",
url: "<?php echo base_url(); ?>index.php/cart/insert_cart",
data:{
head:head, price:price,pid:pid,qty:qty
}
});
});
});
</script>
问题出在您通过 pid
id
head:head, price:price,pid:pid,qty:qty
^^^^^^^^
所以你收到 pid
而不是 id
'id' => $this->input->post('pid'),// here receive pid not id