$request->isAjax() 的实现

gongaiorg

问题描述

$request->isAjax() 的实现

程序代码或配置

原生的ajax请求,需要加
xhr.setRequestHeader('X-Requested-With','XMLHttpRequest');

操作系统环境及workerman/webman等具体版本

window系统

609 1 0
1个回答

walkor

以下是 $request->isAjax() 实现

public function isAjax(): bool
{
    return $this->header('X-Requested-With') === 'XMLHttpRequest';
}

以下是ajax请求头
截图

ajax请求浏览器会自动发送 X-Requested-With 头,用来标记是否是ajax请求。并没有看到你说的requestType头。

🔝