0

MY php code is below:

public function checkWhetherASalaryProcessIsOngoing(){        
    if(isset($this->session->userdata['salary_is_on_going'])){ 
    echo $this->session->userdata['salary_is_on_going'];    }else{echo 'NOTSET';}    
}

public function set_salary_is_on_going(){        
    if(!isset($this->session->userdata['salary_is_on_going'])){$isset = $this->session->set_userdata('salary_is_on_going','SET');} 
    echo $this->session->userdata['salary_is_on_going'];        
}  

public function delete_set_salary_is_on_going(){        

    $this->session->set_userdata('salary_is_on_going','NOTSET');
    echo $this->session->userdata['salary_is_on_going'];
}

My javascript code:

$(document).on('click','a#process',function(){ 
// set the start time
t0 = performance.now();
alert('<?php if(isset($this->session->userdata['salary_is_on_going'])){echo $this->session->userdata['salary_is_on_going'];}?>');

var payment_period_id = parseInt($('#paymentPeriodId').val());
var unit_id = parseInt($('#unitIdz').val());
var user_id = parseInt($('#userIdz').val());    

// check whether same session variables exists in all opened pages. function in D:\xampp\htdocs\diganta\assets\js\common_js.php                
checkSessionDataWithPageSessionData(function(dataii){
if(dataii === 'NOTCHANGED'){

checkWhetherASalaryProcessIsOngoing(function(dataoo){
    if(dataoo === 'NOTSET'){
    // if not set then set session variable named salary_is_on_going    

    set_salary_is_on_going(function(data55){
        if(data55 === 'SET'){

        progress(); 

        var checkedRows = [];
        $("#supervisorList tr").each(function () {

            if ($(this).find("input").is(":checked")) {
                checkedRows.push({"supervisor_id" : $(this).find("td:eq(1)").text()});
            }
        });
            if(checkedRows.length < 1){            
                delete_set_salary_is_on_going();
                custom_alert('Supervisor not selected.',"Error",10,'right',50);
                }    
            if(checkedRows.length > 0){
                ensureItIsNotARevisedSalary(checkedRows,user_id,unit_id,payment_period_id);
            }else{return;}  



        }else{custom_alert('Can not set salary ongoing session variable.',"Error",10,'right',50);return;}            
    });        

    }else{custom_alert('A salary process is ongoing.',"Error",10,'right',50);return;}
});

}else{custom_alert('session data change detected. Cannot Execute.<br><br> refresh.',"Error",10,'right',50);return;}
    });        
 });


function      ensureItIsNotARevisedSalary(checkedRows,user_id,unit_id,payment_period_id){

 var url = '<?php echo base_url();?>primary_salary_processing/ensureItIsNotARevisedSalary';
 $.post(url,{payment_period_id:payment_period_id}).done(function(data){
 data = parseInt(data);
 if(data > 0){        
            setTimeout(function(data){delete_set_salary_is_on_going();},1000);
            custom_alert('This is a revised salary it can not be processed from here.',"Error",120,'right',50);          
        }        
    else{checkWhetherSalaryIsLocked(checkedRows,user_id,unit_id,payment_period_id);}       
}); 
}

function checkWhetherASalaryProcessIsOngoing(result){

var url = '<?php echo base_url();?>primary_salary_processing/checkWhetherASalaryProcessIsOngoing';
$.ajax({
    url:url,
    data:{},  
    type:"POST",
    success:function(data){
         result(data);
     },        
});
}
 function set_salary_is_on_going(result){

var url = '<?php echo base_url();?>primary_salary_processing/set_salary_is_on_going';
$.ajax({
    url:url,
    data:{},  
    type:"POST",
    success:function(data){
         result(data);
     },        
});
}

function delete_set_salary_is_on_going(){

var url = '<?php echo base_url();?>primary_salary_processing/delete_set_salary_is_on_going';
$.ajax({
    url:url,
    data:{'url2':'<?php echo $this->session->userdata['url'];?>'},  
    type:"POST",
    success:function(data){

     },        
    });
}

After clicking a#process the salary process starts.

The problem is javascript function delete_set_salary_is_on_going() cannot change

session variable having index of 'salary_is_on_going' to 'NOTSET'

Hafsul Maru
  • 383
  • 2
  • 12
  • You said in http://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming post than: To call some PHP code, the client will have to send a new HTTP request to the server. This can happen using one of three possible methods: A link, which causes the browser to load a new page. A form submission, which submits data to the server and loads a new page. An AJAX request, which is a Javascript technique to make a regular HTTP request to the server (like 1. and 2. will), but without leaving the current page.Here I am using ajax. Am I wrong. – Hafsul Maru Nov 15 '16 at 03:46

1 Answers1

-1

Did you forget to write session_start() in your receiving/processing url?

<?php session_start() ?>
OBL
  • 367
  • 1
  • 4
  • 13