Laravel在使用Postman时不将请求识别为Ajax
当我从Postman应用程序向Laravel应用程序发出请求时Laravel在使用Postman时不将请求识别为Ajax,ajax,laravel,rest,api,postman,Ajax,Laravel,Rest,Api,Postman,当我从Postman应用程序向Laravel应用程序发出请求时 $request->ajax()未返回TRUE 我还在邮递员中发送Accept:application/json标题,仍然不走运 邮递员请求屏幕截图: 代码截图 添加标题X-request-With:XMLHttpRequest 解释 如果跟踪方法->ajax(),它将执行以下函数: /** * Returns true if the request is a XMLHttpRequest. *
$request->ajax()
未返回TRUE
我还在邮递员中发送Accept:application/json
标题,仍然不走运
邮递员请求屏幕截图:
代码截图
添加标题
X-request-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');
}
添加标题
X-request-With:XMLHttpRequest
,然后$request->ajax()
将返回TRUE
请不要放截图,而是粘贴实际代码