$request->ajax()

Checks if this request is an Ajax request

if(kirby()->request()->ajax()) {
  echo 'This is an ajax request';
}