Request::isXmlHttpRequest PHP Method

isXmlHttpRequest() public static method

It works if your JavaScript library sets an X-Requested-With HTTP header. It is known to work with common JavaScript frameworks:
public static isXmlHttpRequest ( ) : boolean
return boolean true if the request is an XMLHttpRequest, false otherwise
        public static function isXmlHttpRequest()
        {
            //Method inherited from \Symfony\Component\HttpFoundation\Request
            return \Illuminate\Http\Request::isXmlHttpRequest();
        }

Usage Example

 public function sendEmailAction(Request $request)
 {
     if ($request->isXmlHttpRequest()) {
         $data = array();
         $response = new \Symfony\Component\HttpFoundation\JsonResponse();
         $username = $request->request->get('username');
         /** @var $user UserInterface */
         $user = $this->container->get('fos_user.user_manager')->findUserByUsernameOrEmail($username);
         if (null === $user) {
             $data['message'] = $this->trans('resetting.request.invalid_username', array('%username%' => $username));
             $response->setData($data)->setStatusCode(400);
             return $response;
         }
         if ($user->isPasswordRequestNonExpired($this->container->getParameter('fos_user.resetting.token_ttl'))) {
             $data['message'] = $this->trans('resetting.password_already_requested', array());
             $response->setData($data)->setStatusCode(400);
             return $response;
         }
         if (null === $user->getConfirmationToken()) {
             /** @var $tokenGenerator \FOS\UserBundle\Util\TokenGeneratorInterface */
             $tokenGenerator = $this->container->get('fos_user.util.token_generator');
             $user->setConfirmationToken($tokenGenerator->generateToken());
         }
         $this->container->get('fos_user.mailer')->sendResettingEmailMessage($user);
         $user->setPasswordRequestedAt(new \DateTime());
         $this->container->get('fos_user.user_manager')->updateUser($user);
         $data['message'] = $this->trans('resetting.check_email', array('%email%' => $username));
         $response->setData($data);
         return $response;
     } else {
         return parent::sendEmailAction($request);
     }
 }
All Usage Examples Of Request::isXmlHttpRequest