You need to convert the bitval
to an int
before XORing it. So replace the line
var bitval = csv[6];
with
var bitval = parseInt(csv[6]);
The toggling can be then done this way (by moving the bitval declaration out of the onClick handler):
var bitval = null; // this is crucial since you don't have another place to store the value
$(document).on('click', 'input.taster', function() {
var id = $(this).attr('csv');
$.get('plc.php?function=csv&id=' + id, function(data){
// your variables
if (bitval == null) { // initial set
bitval = parseInt(csv[6]); // was 'var bitval = csv[6]'
}
// your load code
bitval ^= 1; // toggle
});
});