/**
* 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:
*
* @link http://en.wikipedia.org/wiki/List_of_Ajax_frameworks#JavaScript
*
* @return bool true if the request is an XMLHttpRequest, false otherwise
*
* @api
*/
public function isXmlHttpRequest()
{
return 'XMLHttpRequest' == $this->headers->get('X-Requested-With');
}
并不能的,xhr也是执行了HTTP提交,默认情况的头都是一样的。不过如果你前端用的是JQ,那会加入x-requested-with的头的。
嗯 输出这个对比下 $_SERVER["HTTP_X_REQUESTED_WITH"]
laravel中AJAX的判断,不是标准头也是业内标准了。