Session is loading after page reload in codeigniter

106
August 07, 2019, at 2:50 PM

I have a points table in which I have email and points column, I want to increase the points when somebody clicks on a button using ajax which I am sending to the controller , I am loading session there and checking this session exist then increase the points per 5 seconds , It is only working after reloading the page

here is my button click code from front page front.php

$(document).off('click','#earn_points').on('click','#earn_points',function(){
    var increament_var = 'plus1';
    $.ajax({
        url:'<?php echo base_url("front_controller/points_session") ?>',
        type:"POST",
        data:{increament_var:increament_var},
        dataType:"json",
        success:function(data)
        {
          console.log(data);
        }
    });
});

and here is my points_session function from Front_controller

function points_session()
{
    $increament_var = $this->input->post('increament_var');
    if($increament_var=='plus1')
    {
        $this->session->set_userdata('increament',$increament_var);
    }
    echo json_encode($this->session->userdata('increament'));
}

And after doing that I am also checking if this increment session exist then increase points per 3 seconds on front.php page

if($this->session->has_userdata('increament') &&  $this->session->has_userdata('email'))
{ 
    var ins =1;
    setInterval(function(){   
        $.ajax({
        url : "<?php echo base_url('front_controller/increase_points') ?>",
        type:'POST',
        data:{ins:ins},
        dataType:"json",
        success:function(data)
        {
            console.log(data);
            if(data.result==true)
            {
                alert(1 points has been added to your account);
            }
        }
    }); }, 3000);
}

and here is increase_points function in front_controller

 function increase_points()
 {
    $ins = $this->input->post('ins');
    if($ins==1)
    {
        $email =$this->session->userdata('email');
        $query_update = $this->db->set('points','points+1',FALSE)
        ->where('email',$email)
        ->update('users');
        if($query_update)
        {
            $res = array('result'=>true);
        }
        else
        {
            $res = array('result'=>false);
        }
        echo json_encode($res);
    }
}

I do not want to increase points on reloading the page, everything is working fine but after page reloading. I do not want to reload the page. I want to increase the points without reloading the page

READ ALSO
Math Operations with Javascript in DIV created dinamically with classes

Math Operations with Javascript in DIV created dinamically with classes

After creating divs dynamically with class="sizetot"; i want to reset it's values when the sum of each div created is > to a certain number (storagemax) picked correctly from the database with phpI have some problems, last divs created won't change their values

32
How can I hide code blocks in xaringan presentation?

How can I hide code blocks in xaringan presentation?

I'm running some plot code in markdown to generate a plot in a xaringan presentationThe code works but is a little long and so takes up the whole presentation slide forcing the actual plot off the edge (see img)

125
Where to write custom SCSS in Bootstrap 4

Where to write custom SCSS in Bootstrap 4

I am developing ASPNET website with bootstrap

128