I ran into issue with sessions
and ajax
. I have this peace of code:
for ($i=0; $i < count($result); $i++) {
if(in_array($result[$i], $m_lines_arr)) {
echo "<p class='br' style='color: #ffffff'>Match on comb. $i</p>";
$win = 10;
$this->session->set_userdata( array('win' => $win));
}
else {
echo "<p class='br'>No match on comb. $i</p>";
}
}
So, if something is in array, give $win
value 10
and save it do session, otherwise just do simple echo.
In my function win
I try to echo
this session
. Here is the sample of function win
:
function win() {
$win = $this->input->post('win');
echo $this->session->userdata('win');
}
Function win
comes after the for loop
, just for you to know.
And here is the Ajax request:
var win = $('#win span').html();
$.ajax({
type: 'POST',
url: 'http://localhost/slots/index.php/game/win',
data: { win: win },
success:function(response) {
$('#win span').html(response);
}
});
The problem is, I can't display data stored in session in real time, I must refresh page to get the result. Any clue?