diff --git a/extend/base/admin/controller/system/AdminBase.php b/extend/base/admin/controller/system/AdminBase.php index dacd721..23224dc 100644 --- a/extend/base/admin/controller/system/AdminBase.php +++ b/extend/base/admin/controller/system/AdminBase.php @@ -44,7 +44,7 @@ class AdminBase extends AdminController */ public function index() { - if ($this->request->isJson()) { + if ($this->request->isAjax()) { if (input('selectFields')) { return $this->selectList(); } diff --git a/extend/base/common/controller/AdminControllerBase.php b/extend/base/common/controller/AdminControllerBase.php index 31171a2..72eefdb 100644 --- a/extend/base/common/controller/AdminControllerBase.php +++ b/extend/base/common/controller/AdminControllerBase.php @@ -222,7 +222,7 @@ class AdminControllerBase extends BaseController public function checkParseApi() { if (Config::get('app.auto_parse_api')) { - if ($this->request->isJsonPure() && $this->request->param('get_page_data')) { + if ($this->request->isJson() && $this->request->param('get_page_data')) { return true; } } diff --git a/extend/base/common/provider/RequestBase.php b/extend/base/common/provider/RequestBase.php index 96b30d7..b671dff 100644 --- a/extend/base/common/provider/RequestBase.php +++ b/extend/base/common/provider/RequestBase.php @@ -10,35 +10,34 @@ class RequestBase extends \think\Request protected $filter = []; /** - * 当前是否JSON请求 + * 当前是否Ajax请求 + * @access public + * @param bool $ajax true 获取原始ajax请求 * @return bool */ - public function isJson(): bool + public function isAjax(bool $ajax = false): bool { - $acceptType = $this->type(); + $value = $this->server('HTTP_X_REQUESTED_WITH'); + $result = $value && 'xmlhttprequest' == strtolower($value) ? true : false; - $is_json = str_contains($acceptType, 'json'); - if (!$is_json) { - return false; + if (true === $ajax) { + return $result; } + $is_ajax = $this->param($this->varAjax) ? true : $result; + if (!Config::get('app.auto_parse_api')) { + return $is_ajax; + } + + if($this->isJson()){ + if ($this->has('get_page_data')) { + return false; + } return true; } - if ($this->has('get_page_data')) { - return false; - } - return true; + return $is_ajax; } - /** - * 仅通过实际请求参数判断请求 - * - * @return bool - */ - public function isJsonPure() - { - return parent::isJson(); - } }