let route = "{{ route('srcname') }}";
let token = "{{ csrf_token()}}";
$.ajax({
url: route,
type: 'POST',
data: {
_token:token,
name:'name',
email:'email'
phone:'09876767'
},
success: function(response) {
console.log(response)
},
error: function(xhr) {
//Do Something to handle error
}});
}
// laravel web
Route::post('srcname', [Controllername::class, 'filter'])->name('srcname');
// Controller
public function filter(Request $request){ return $request->name ;}
$.ajax({
url: "/route/to",
type: 'POST',
beforeSend: function (request) {
return request.setRequestHeader('X-CSRF-Token', $("meta[name='csrf-token']").attr('content'));
},
success: data => {
console.log(data);
}
});