In my Laravel app, I am using Fetch API to load data on scroll. Below is my JS code in blade file
let route = '{{ route("load") }}' + '?q=' + encodeURI('{{ $para }}');
fetch(route)
.then(response => {
if(!response.ok) {
throw new Error('Network response was not ok');
}
return response.text();
})
.then(data => {
console.log(data);
})
.catch((error) => {
console.error('Error:', error);
})
And in my controller
public function loadData( Request $request )
{
if( $request->ajax() ) {
return $request->query('q');
}
return 'Not Ajax!';
}
It always return 'Not Ajax!';
I am not sure why this is happening. It was not a problem with other libraries like jQuery or Axios