Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. Request.php

function Request::isXmlHttpRequest

Returns true if the request is an XMLHttpRequest.

It works if your JavaScript library sets an X-Requested-With HTTP header. It is known to work with common JavaScript frameworks:

See also

https://wikipedia.org/wiki/List_of_Ajax_frameworks#JavaScript

File

vendor/symfony/http-foundation/Request.php, line 1710

Class

Request
Request represents an HTTP request.

Namespace

Symfony\Component\HttpFoundation

Code

public function isXmlHttpRequest() : bool {
    return 'XMLHttpRequest' == $this->headers
        ->get('X-Requested-With');
}
RSS feed
Powered by Drupal