From 9ab50f1a9234ec1ef8512646e7b65d1f7cf4776e Mon Sep 17 00:00:00 2001 From: thinkphp Date: Sat, 19 Dec 2015 11:34:17 +0800 Subject: [PATCH] =?UTF-8?q?response=E7=9A=84returnData=E6=96=B9=E6=B3=95?= =?UTF-8?q?=E5=A2=9E=E5=8A=A0content-length=E8=AE=BE=E7=BD=AE=20#90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- library/think/response.php | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/library/think/response.php b/library/think/response.php index 60f7faac..9ae3c0b2 100644 --- a/library/think/response.php +++ b/library/think/response.php @@ -52,6 +52,7 @@ class Response $data = $handler . '(' . \org\Transform::jsonEncode($data) . ');'; break; } + header('Content-Length:' . strlen($data)); if ($exit) { exit($data); } else { @@ -88,15 +89,16 @@ class Response * @param mixed $wait 返回数据格式 * @return void */ - public static function success($msg = '', $data = '', $url = '', $wait = 3){ - $result = [ + public static function success($msg = '', $data = '', $url = '', $wait = 3) + { + $result = [ 'code' => 1, 'msg' => $msg, 'data' => $data, - 'url' => $url ? $url: $_SERVER["HTTP_REFERER"], + 'url' => $url ? $url : $_SERVER["HTTP_REFERER"], 'wait' => $wait, ]; - $type = IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type'); + $type = IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type'); if ('html' == $type) { $view = new \think\View(); $result = $view->fetch(Config::get('dispatch_jump_tmpl'), $result); @@ -113,15 +115,16 @@ class Response * @param mixed $wait 返回数据格式 * @return void */ - public static function error($msg = '', $data = '', $url = '', $wait = 3){ - $result = [ + public static function error($msg = '', $data = '', $url = '', $wait = 3) + { + $result = [ 'code' => 0, 'msg' => $msg, 'data' => $data, 'url' => $url ? $url : 'javascript:history.back(-1);', 'wait' => $wait, ]; - $type = IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type'); + $type = IS_AJAX ? Config::get('default_ajax_return') : Config::get('default_return_type'); if ('html' == $type) { $view = new \think\View(); $result = $view->fetch(Config::get('dispatch_jump_tmpl'), $result);