diff --git a/convention.php b/convention.php index 83431ab3..f7486a48 100644 --- a/convention.php +++ b/convention.php @@ -95,6 +95,10 @@ return [ 'url_controller_layer' => 'controller', // 表单请求类型伪装变量 'var_method' => '_method', + // 表单ajax伪装变量 + 'var_ajax' => '_ajax', + // 表单pjax伪装变量 + 'var_pjax' => '_pjax', // +---------------------------------------------------------------------- // | 模板设置 diff --git a/library/think/Request.php b/library/think/Request.php index a7b50ba8..6c19c44a 100644 --- a/library/think/Request.php +++ b/library/think/Request.php @@ -1186,22 +1186,34 @@ class Request /** * 当前是否Ajax请求 * @access public + * @param bool $ajax true 获取原始ajax请求 * @return bool */ - public function isAjax() + public function isAjax($ajax = false) { - $value = $this->server('HTTP_X_REQUESTED_WITH'); - return (!is_null($value) && strtolower($value) == 'xmlhttprequest') ? true : false; + $value = $this->server('HTTP_X_REQUESTED_WITH', '', 'strtolower'); + $result = ('xmlhttprequest' == $value) ? true : false; + if (true === $ajax) { + return $result; + } else { + return $this->param(Config::get('var_ajax')) ? true : $result; + } } /** * 当前是否Pjax请求 * @access public + * @param bool $pjax true 获取原始pjax请求 * @return bool */ - public function isPjax() + public function isPjax($pjax = false) { - return !is_null($this->server('HTTP_X_PJAX')) ? true : false; + $result = !is_null($this->server('HTTP_X_PJAX')) ? true : false; + if (true === $pjax) { + return $result; + } else { + return $this->param(Config::get('var_pjax')) ? true : $result; + } } /**