Laravel 在使用 Postman 时无法将 Request 识别为 Ajax

Har*_*ngh 3 api ajax rest laravel postman

当我从 Postman 应用程序向 Laravel 应用程序提出请求时,

$request->ajax() 不返回TRUE。

我也在Accept: application/json邮递员中发送标头,仍然没有运气。

邮递员请求截图

邮递员请求截图

代码截图

代码截图

Chr*_*ert 8

添加标题 X-Requested-With: XMLHttpRequest

说明

如果您跟踪该方法,->ajax()它将通过以下功能:

    /**
     * Returns true if the request is a XMLHttpRequest.
     *
     * It works if your JavaScript library sets an X-Requested-With HTTP header.
     * It is known to work with common JavaScript frameworks:
     *
     * @see https://wikipedia.org/wiki/List_of_Ajax_frameworks#JavaScript
     *
     * @return bool true if the request is an XMLHttpRequest, false otherwise
     */
    public function isXmlHttpRequest()
    {
        return 'XMLHttpRequest' == $this->headers->get('X-Requested-With');
    }
Run Code Online (Sandbox Code Playgroud)

添加标题X-Requested-With: XMLHttpRequest,然后$request->ajax()将返回TRUE