I'm trying to delete
a record in mysql
in laravel
application. But it shows TokenMismatchException error. I am not able to find why its throwing error. It would be great if anyone can help out..
here's view code: (I don't have a form)
<a href="{{url('/page/'.$Ids->id)}}" class="remove-entry">
<button type="button" class="close" aria-label="Close"><span aria-hidden="true">×</span></button>
</a>
And here's jQuery AJAX call:
$(document).on('click', '.remove-entry', function(e){
e.preventDefault();
$.ajax({
url: this.href,
type: 'DELETE',
data: {
"_token": "{{ csrf_token() }}"
},
success: function(res) {
console.log('removed');
}
});
});
UPDATE
I tired the following code but it doesn't work probably because it needs to have value token
which I suppose is to be fetched from form. But as I already mentioned above, I DON'T have a form set-up. So how can I put the token
value in that case?
headers: {'X-CSRF-TOKEN': token}
I understand the problem I'm facing is not new or unique, but it surely is different from the questions that it is supposedly considered duplicate of. Also, the code worked fine earlier but its creating issues in new project
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…