douniangliao4327 2014-07-07 10:32
浏览 38

如果插入是由AJAX完成的,如何在codeigniter会话中存储最后一个插入ID?

I need to insert last insert id of user on some event ..... And I want to get that on another page.... Like On product page ....user customizing his product....like mug customization

And i need to get the inserted....customization product id to the cart page and this is done by ajax....so how can i get last insert id on cart page from product page....

my ajax...

$('#store').click(function () {

    $.ajax({
        type: "POST",
        url: ajax_url_store,
        data: {
            action: 'store',
            views: JSON.stringify(thsirtDesigner.getProduct())
        },

        success: function (data) {

            if (parseInt(data) > 0) {
                //successfully added

                document.getElementById('succes-message').innerHTML = 'You Design has Been SuccessFully Saved';
            } else {

            }

        },
        error: function () {
            //alert('some error has occured...');
        },
        start: function () {
            //alert('ajax has been started...');    
        }
    });
});

My ci function

public function saveData() {

    if ($this - > input - > post('action') == 'store') {

        $views = $this - > input - > post('views');
        $id = $this - > product_model - > save($views);

        if ($id != '') {
            header('Content-Type: application/json');
            echo json_encode($id);
        }
    }
}
  • 写回答

1条回答 默认 最新

  • douyong1905 2014-07-07 10:44
    关注
    public function saveData() 
    {
    
      if ($this->input->post('action') == 'store') 
      {
    
        $views = $this->input->post('views');
        $id = $this->product_model->save($views);
        $data = array('userid'=>$id);       //insert id to userid as session variable
        $this->session->set_userdata($data);  //set userid as a session variable
    
        if ($id != '') 
        {
            header('Content-Type: application/json');
            echo json_encode($id);
        }
      }
    }    
    
    评论

报告相同问题?

悬赏问题

  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥30 python代码,帮调试,帮帮忙吧