I think you should add,
meta tag with name = "csrf-token" and with content = {{ csrf_token() }}
to your head section of view. have you done that?
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I'm trying to do ajax here. can someone show me what i'm doing wrong?
here is my js file
$('.stagestrip:not(.dd)').on('click',function(){
$.ajaxSetup({
headers: {
'X-CSSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
var stage = $(this).attr('data-stage');
$.ajax({
url: baseurl+'leads/updatestage/'+ $('#lead_slug').val(),
type: 'POST',
data: {'status':stage},
success: function (data) {
toastr["success"](data, "Success");
}
});
});
here is my controller
if($request->ajax()) {
$data = array(
'lead_status2' => $request->status
);
Leads::where('lead_slug',$id)->update($data);
}
Thanks.
@pordonez I know it's been more than a week.
If still you couldn't make out the error, please find below details.
You posted:
$.ajaxSetup({
headers: {
'X-CSSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
But there is a typo, please check the corrected version
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
Please or to participate in this conversation.