在对代码点火器中的函数进行ajax jquery调用后,会话值被销毁


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