I am submitting a form using ajax with enabling CSRF protection to true in config.php. First time, the form is submitting well but second time it's showing error "Forbidden. The Action you requested is not allowed. 403". How can I securely submit form using ajax by enabling CSRF protection to true. Below is the ajax function I am using.
$('#loginfrmbtn').on('click', function(){
$(this).prop('disabled', true);
var formdata=$('#loginfrm').serialize();
$.ajax({
type: 'POST',
data: formdata,
url: '<?php echo base_url('logincheck');?>',
dataType: 'json',
success: function(res){
$('#loginfrmbtn').prop('disabled', false);
console.log(res);
}, error: function(jqXHR){
console.log(jqXHR);
}
})
})