The request object available inside Drupal has a method called "isXmlHttpRequest" that allows the detection of ajax requests.
/** @var \Symfony\Component\HttpFoundation\Request $request */
$request = \Drupal::request();
$isAjax = $request->isXmlHttpRequest();
Use this check when you want to perform different actions during an ajax request.
Add new comment