Return a success JSON response.

@param  string $message
@param  string $redirectTo

@return JSON
975372
public function respondsWithSuccess(string $message, string $redirectTo = '')
    {
        return response()->json([
            'redirectTo' => $redirectTo,
            'callback' => $redirectTo,
            'message' => $message,
            'success' => true,
        ], 200);
    }
798610
public function success($message = null, $data = array(), $return = false)
    {
        if (!empty($data)) {
            foreach ($data as $key => $value) {
                $this->add($key, $value);
            }
        }
        $json = $this->jsonEncode(
            array(
                'success' => true,
                'message' => $message,
                'data' => $this->_data,
            )
        );
        if (!$return) {
            echo $json;
            Yii::app()->end();
        } else {
            return $json;
        }
    }
1115530
static public function redirect($routeFrom, $routeTo, $http_response_code = 302)
    {
        $closure = function($routeTo, $replace, $http_response_code) {
            Response::$redirectHeader = [$routeTo, $replace, $http_response_code];
        };
        self::$instance->register('GET', $routeFrom, $closure, null, [$routeTo, true, $http_response_code]);
    }
739343
def _get_request_content(self, message=None):
        '''
        '''
        if not message:
            raise MessageError('No messages to send.')
        if len(message) > MAX_BATCH_MESSAGES:
            err = 'Maximum {0} messages allowed in batch'
            raise MessageError(err.format(MAX_BATCH_MESSAGES))
        message = [self._cast_message(message=msg) for msg in message]
        message = [msg.data() for msg in message]
        return json.dumps(message, ensure_ascii=True)
793917
public function redirect($url, $message = null, $type = 'success')
	{
		$redirect = new RedirectResponse($url);
		$redirect->setRequest($this['request']);

		if ($message && $this->has('notification'))
		{
			$this['notification']->message($message, $type);
		}

		$redirect->send();

		$this->close();
	}
249637
private static function errorJson($statusCode, $message)
    {
        $output = ['error' => $statusCode];

        if (!empty($message)) {
            $output['message'] = $message;
        }

        return json_encode($output);
    }
62276
public function aSuccess($message,$url='',$data=[])
    {
        $url=is_null($url) || $url=='' ? 'javascript:history.back(-1)' : $url;
        if(Request::isAjax() ){
            return $this->json(0,$message,array_merge($data,['url'=>url($url)]));
        }else{
            return $this->success($message,$url);
        }
    }
40030
public function error($message, $return = false)
    {
        $json = $this->jsonEncode(
            array(
                'error' => true,
                'message' => $message,
            )
        );
        if (!$return) {
            echo $json;
            Yii::app()->end();
        } else {
            return $json;
        }
    }
1333585
function json($data = '', $code = 0, $message = '')
    {
        $json = array('code' => $code, 'message' => $message, 'data' => $data);
        if (!empty($_REQUEST['jsonp']))
        {
            $this->http->header('Content-type', 'application/x-javascript');
            return $_REQUEST['jsonp'] . "(" . json_encode($json) . ");";
        }
        else
        {
            $this->http->header('Content-type', 'application/json');
            return json_encode($json);
        }
    }
826969
public function flash($message, $status = 'error', $redirect = null) {
        return $this->message($message, $status, $redirect, 'flash');
    }
112092
def update_redirect_to_from_json(page, redirect_to_complete_slugs):
    
    messages = []
    s = ''
    for lang, s in list(redirect_to_complete_slugs.items()):
        r = Page.objects.from_path(s, lang, exclude_drafts=False)
        if r:
            page.redirect_to = r
            page.save()
            break
    else:
        messages.append(_("Could not find page for redirect-to field"
            " '%s'") % (s,))
    return messages
939163
public function delete(Redirect $redirect)
    {
        $this->authorize(RedirectsPolicy::PERMISSION_DELETE);

        $redirect->delete();

        return $this->jsonResponseSuccess([
            'message' => $this->transNotification('deleted', [], $redirect->toArray())
        ]);
    }
241917
public function json($status_code, $message, $data = null)
    {
        return response()->json([
                                    'status_code' => $status_code,
                                    'message'     => $message,
                                    'data'        => $data,
                                    'request'     => \request()->all(),
                                ]);
    }
1257355
public function message($message, $success = 0, $return = false)
    {
        $array = array(
            'success' => $success,
            'message' => $message
        );

        $url = $this->saveURL . $this->saveName;

        // Cross-domain redirect to callback url
        if ($this->redirect)
        {
            $this->redirectURL .= '&success=' . $success . '&message=' . $message;

            if ($success == 1)
            {
                $this->redirectURL .= '&url=' . $url;
            }

            $this->redirect();
        }
        else
        {
            echo "success =>" . $success;
            if ($success == 1)
            {
                $array['url'] = $url;
            }

            $this->message = $array = json_encode($array);

            if ($return)
            {
                return $array;
            }
            else
            {
                echo $array;
            }
        }
    }
560821
public function handleJsonResponse($success = false, $retVars = null)
    {
        $result = array();
        if ($success) {
            $result = array(
                'success' => $success
            );
        }
        if ($retVars) {
            $result = array_merge($retVars, $result);
        }

        $response = new SS_HTTPResponse(json_encode($result));
        $response->addHeader('Content-Type', 'application/json');
        return $response;
    }
4788
protected function fail($message = null, $validation = null)
    {
        $this->trigger('json-fail', $this, $message, $validation);
        $this->trigger('response-fail', $this, $message, $validation);

        $json = array('error' => true);

        if($message) {
            $json['message'] = $message;
        }

        if($validation) {
            $json['validation'] = $validation;
        }

        $body = json_encode($json, JSON_PRETTY_PRINT);

        $this->response
            ->set('headers', 'Content-Type', 'text/json')
            ->set('body', $body);

        return $body;
    }
199851
protected function buildResponse($to, $from, $message)
    {
        if (empty($message) || $message === self::SUCCESS_EMPTY_RESPONSE) {
            return self::SUCCESS_EMPTY_RESPONSE;
        }

        if ($message instanceof RawMessage) {
            return $message->get('content', self::SUCCESS_EMPTY_RESPONSE);
        }

        if (is_string($message) || is_numeric($message)) {
            $message = new Text(['content' => $message]);
        }

        if (!$this->isMessage($message)) {
            $messageType = gettype($message);
            throw new InvalidArgumentException("Invalid Message type .'{$messageType}'");
        }

        $response = $this->buildReply($to, $from, $message);

        Log::debug('Message safe mode is enable.');
        $response = $this->encryptor->encryptMsg(
            $response,
            $this->request->get('nonce'),
            $this->request->get('timestamp')
        );

        return $response;
    }