PHP 8.6.0 Beta 3 is available for testing

Yaf_Request_Abstract::isXmlHttpRequest

(Yaf >=1.0.0)

Yaf_Request_Abstract::isXmlHttpRequestDetermine if the request is an Ajax request

Descrizione

public function Yaf_Request_Abstract::isXmlHttpRequest(): bool

Checks whether the request is an Ajax request by inspecting the HTTP_X_REQUESTED_WITH request header.

Nota:

Yaf_Request_Simple overrides this method and always returns false, since command-line requests are never Ajax requests.

Elenco dei parametri

Questa funzione non contiene parametri.

Valori restituiti

Returns true if the request is an Ajax request (the X-Requested-With header equals XMLHttpRequest), false otherwise.

Esempi

Example #1 Yaf_Request_Abstract::isXmlHttpRequest() example

<?php
class ProductController extends Yaf_Controller_Abstract
{
    public function viewAction()
    {
        // Assuming the request carries "X-Requested-With: XMLHttpRequest"
        if ($this->getRequest()->isXmlHttpRequest()) {
            $this->getResponse()
                 ->setHeader("Content-Type", "application/json")
                 ->setBody(json_encode(["id" => 17, "name" => "Yaf in Action"]));
            return false;
        }
    }
}
?>

Il precedente esempio visualizzerà qualcosa simile a:

{"id":17,"name":"Yaf in Action"}

Vedere anche:

add a note

User Contributed Notes 1 note

up
0
oreaking at gmail dot com
11 years ago
That means the request method is ajax or not .
To Top