From 22839ae92216c5112bf7d2f6f42bcff1b8d1d7fd Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Mon, 17 Jun 2013 17:10:20 -0400 Subject: [PATCH] Fixed jsonp response handling. --- framework/yii/web/Response.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/framework/yii/web/Response.php b/framework/yii/web/Response.php index 56e2b3e..48b7e5e 100644 --- a/framework/yii/web/Response.php +++ b/framework/yii/web/Response.php @@ -706,8 +706,7 @@ class Response extends \yii\base\Response /** * Prepares for sending the response. * The default implementation will convert [[data]] into [[content]] and set headers accordingly. - * @throws InvalidParamException if `$format` is not supported - * @throws InvalidConfigException if the formatter for the specified format is invalid + * @throws InvalidConfigException if the formatter for the specified format is invalid or [[format]] is not supported */ protected function prepare() { @@ -744,10 +743,11 @@ class Response extends \yii\base\Response $this->getHeaders()->set('Content-Type', 'text/javascript; charset=' . $this->charset); if (is_array($this->data) && isset($this->data['data'], $this->data['callback'])) { $this->content = sprintf('%s(%s);', $this->data['callback'], Json::encode($this->data['data'])); - break; } else { - throw new InvalidParamException("The 'jsonp' response requires that the data be an array consisting of both 'data' and 'callback' elements."); + $this->content = ''; + Yii::warning("The 'jsonp' response requires that the data be an array consisting of both 'data' and 'callback' elements.", __METHOD__); } + break; case self::FORMAT_XML: $this->content = Yii::createObject(XmlResponseFormatter::className())->format($this); break;