我需要在某些事件中插入用户的最后插入 ID ..... 我想把它放在另一页上...... 喜欢在产品页面....用户定制他的产品...喜欢mug customization
我需要将插入的....自定义产品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...');
}
});
});
我的 ci 函数
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);
}
}
}
关于php - 如果插入是通过 AJAX 完成的,如何在 codeigniter session 中存储最后的插入 id?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24608541/