i can`t store session value passing through jquery ajax. in codeigniter php framework -
i have problem storing session value; not able increment session count variable via ajax jquery call value passing function, set array stores session change new one.
what problem here:
1>when use 1 controller function
startonlinetest($testid=0) set session countnew 0 $this->session->set_userdata('countnew',0); , in view use jquery pass data other function of same controller public function responseonline($qid,$response)
using change effect of jquery
echo "[removed]$(document).ready(function(){"; foreach($question['childquestion'] $q=>$aq){ // echo "\$(\"input:radio[name=qid-$q]\").live('change',function(){ var sr=\$(\"input:radio[name=qid-$q]:checked\").map(function() { return $(this).val(); }).get().join(); var qid = \$(\"input:radio[name=qid-$q]\").attr(\"qaid\"); "; echo "\$.get('"; echo base_url();echo "testpapers/responseonline/'+qid+'/'+sr,{},function(data) {\$('#res').html(data)}); });";} echo"});[removed]" ;// script working fine
now problem session value overwrite current 1 although use array code responseonline is
public function responseonline($qid,$response) { echo "this" .$this->session->userdata('countnew'); // not echo set above function startonlinetest($testid=0)[/color] set session countnew $this->session->set_userdata('countnew',0) echo $d=$qid; // know no use save time tested on $d $s=$response; if($this->session->userdata('countnew')==0) // algo function check //countnew session varaible if 0 { $sc=$this->session->userdata('countnew'); // store countnew variable echo $sc=$sc+1; // increment counter variable $this->session->set_userdata('countnew',$sc); // store in session echo "this incrementes session value"; echo $this->session->userdata('countnew'); $r2[$d]=$s; // store array value $r2 key $d , value $s $this->session->set_userdata('res',$r2); //set array value in session } else{ // if session countnew!=0 $r2=$this->session->userdata('res'); // first store $r2 array return session $r2[$d]=$s; //then add value array $this->session->set_userdata('res',$r2); // storing array session } echo '<pre>'; print_r($r2); // printing array }
i result first call fine second call value overwrite session show array([32323]=>23))
if pass function (32323,23)
if pass (33,42)
array([33]=>42)
old value destroyed.
you should use regular sessions in php because sessions in codeigniter allow store single item. this:
$_session['item'][] = $array;
or maybe still use codeigniter sessions doing this:
$items = $this->session->userdata('items'); array_push($items, $new_item); $this->session->set_userdata('items', $items);
if want define keys well:
$items = $this->session->userdata('items'); $items['your_key'] = $new_item; $this->session->set_userdata('items', $items);
Comments
Post a Comment