[英]Session value is destroyed after ajax jquery call to function in codeigniter
當我通過ajax jQuery將一些值傳遞給function ResponseOnline($qid,$response)
時,我無法同時存儲新的會話值和舊的會話值。
這是我的問題
1 。 登錄會話后存儲一些值
2 。 然后,我將一些值傳遞給通過ajax jquery起作用的函數,並將其存儲在數組中,然后在會話中。
3 。 當我通過ajax jQuery獲取會話值時,我做對了,
4 。 但是,當我傳遞第二個值時,則會丟失存儲在上一遍中的會話值。
這是我的函數調用:
public function ResponseOnline($qid,$response)
{
$d=$qid;
$s=$response;
if($this->session->userdata('countnew')==0) // algo for this function i check the
//countnew session varaible if 0 do this
{
$sc=$this->session->userdata('countnew'); // store the countnew variable
echo $sc=$sc+1; // increment the counter variable
$this->session->set_userdata('countnew',$sc); // store it in session
echo $this->session->userdata('countnew');
$r2[$d]=$s; // store array value $r2 with key $d and
$this->session->set_userdata('res',$r2); //set this array value in session
}
else{ // if session countnew!=0 then do this
$r2=$this->session->userdata('res'); // first store $r2 as array return from session
$r2[$d]=$s; //then add value to this array
$this->session->set_userdata('res',$r2); // storing this array to session
}
echo '<pre>';
print_r($r2); // printing the array
}
public function ResponseOnline($qid,$response)
{
if($this->session->userdata('res'))
{
$result = $this->session->userdata('res');
$result[$qid] = $response;
$this->session->set_userdata($result);
}
else
{
$result = array();
$result[$qid] = $response;
$this->session->set_userdata($result);
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.