From f5f9fcfb92201e63a493aff3769b35284e13ad7a Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sun, 25 Sep 2016 19:31:06 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=AF=E6=8C=81=E8=A1=A8=E5=8D=95=E6=A8=A1?= =?UTF-8?q?=E6=8B=9Fajax=E5=92=8Cpjax=E8=AF=B7=E6=B1=82=20=E5=A2=9E?= =?UTF-8?q?=E5=8A=A0var=5Fajax=20var=5Fpjax=20=E9=85=8D=E7=BD=AE=E5=8F=82?= =?UTF-8?q?=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- convention.php | 4 ++++ library/think/Request.php | 22 +++++++++++++++++----- 2 files changed, 21 insertions(+), 5 deletions(-) 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; + } } /**