I have a global variable var emp_error = 0; but when I access emp_error even though it when through else (since the tr's bg color changes), emp_error is still 0. Can someone help me out? So that it won't update the employee ID if it already exists
$.ajax({
     type: "POST",
     url: "<?php echo site_url('c_device/check_empId'); ?>",
     data: dataString,
     dataType: 'json',
     cache: false,
     success: function(data){
              console.log(data);
              if(data.length == 0){
                   emp_error=0;
              }else{
                   $("#error_"+tr_id).html("Emp id exists");    
                   $("#"+tr_id).css("background-color","red");                  
                   emp_error++;
              }                  
     }
});
 
     
    