如果插入是由AJAX执行的,如何在编码器会话中存储最后的插入id


How to store last insert id in codeigniter session if insert is donr by AJAX?

我需要在一些事件.....上插入用户的最后插入id我想把它放到另一页....比如在产品页面....用户定制他的产品....喜欢马克杯定制

我需要得到插入....定制产品id到购物车页面,这是通过ajax....完成的那么如何从产品页面....

获取购物车页面上的最后插入id呢?

我的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);
        }
    }
}
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);
    }
  }
}