Display ajax response.

@return \Illuminate\Http\JsonResponse
974804
public function ajax()
    {
        return datatables($this->query())
            ->setTransformer(app($this->transformer))
            ->filterColumn('country_code', function (Builder $builder, $keyword) {
                $countryCode = collect(countries())->search(function ($country) use ($keyword) {
                    return mb_strpos($country['name'], $keyword) !== false || mb_strpos($country['emoji'], $keyword) !== false;
                });

                ! $countryCode || $builder->where('country_code', $countryCode);
            })
            ->filterColumn('language_code', function (Builder $builder, $keyword) {
                $languageCode = collect(languages())->search(function ($language) use ($keyword) {
                    return mb_strpos($language['name'], $keyword) !== false;
                });

                ! $languageCode || $builder->where('language_code', $languageCode);
            })
            ->orderColumn('name', 'name->"$.'.app()->getLocale().'" $1')
            ->make(true);
    }
1017935
public function render()
    {
        $params     = isset($this->params['attributes']) ? $this->params['attributes'] : $this->params;
        $id         = !isset($params['id']) ? $params['name'] . '-' . str_random(4) : $params['id'];
        $script     = $this->script($id, $params);
        $attributes = app('html')->decorate(array_except($params + ['id' => $id], ['pluginOptions', 'options']));


        $optionsData = array_get($this->params, 'optionsData', []);
        $control     = app('form')->select(
                array_get($this->params, 'name'), array_get($this->params, 'options', []), array_get($this->params, 'value'), $attributes, $optionsData
        );
        echo view('antares/html::controls.remote_select', ['control' => $control])->render();
        if (app('request')->ajax()) {
            echo '<script type="text/javascript">' . $script . '</script>';
        } else {
            app('antares.asset')->container('antares/foundation::scripts')->inlineScript('remote-select-' . $id, $script);
        }
        return '';
    }
1169454
protected function getErrorResponse()
    {
        if (Request::ajax()) {
            throw new AjaxException('Element not found');
        }

        return Response::make($this->controller->run('404')->getContent(), 404);
    }
947442
public function getRouterJavascriptResponse()
    {

        $fh = fopen('php://temp', 'rw');
        $stream = new Stream($fh);

        $stream->write($this->getRouterJavascript());

        return (new Response())
            ->withBody($stream)
            ->withHeader('Content-Type', 'application/javascript');
    }
1019960
public function actionJson()
    {
        /** @var \yii\web\Response */
        $response = \Yii::$app->getResponse();
        
        if (!is_readable($this->module->swaggerPath)) {
            throw new NotFoundHttpException();
        }
        
        // Read source json file
        $json = file_get_contents($this->module->swaggerPath);
    
        // Do replacements
        if (is_array($this->module->swaggerReplace)) {
            foreach ($this->module->swaggerReplace as $find => $replace) {
                if (is_callable($replace)) {
                    $replaceText = call_user_func($replace);
                } else {
                    $replaceText = (string) $replace;
                }
                $json = mb_ereg_replace((string)$find, $replaceText, $json);
            }
        }
        
        // Override default response formatters
        // To avvoid json format modification
        $response->format = Response::FORMAT_RAW;
        $response->getHeaders()->set('Content-Type', 'application/json; charset=UTF-8');
        
        // Trigger events
        $event = new BeforeJsonEvent;
        $event->responseText = $json;
        $this->module->trigger(self::EVENT_BEFORE_JSON, $event);
        
        return $event->responseText;
    }
306042
public function render()
    {
        $returnValue = $this->renderLabel();
        
        if (empty($this->value) === true) {
            // @todo should be in a blue info box.
            $returnValue .= "No values to display.";
        } elseif (($jsonObject = @json_decode($this->value)) === null) {
            // @todo should be in a red error box.
            $returnValue .= "Invalid value.";
        } else {
            // Valid JSON to be displayed.
            $returnValue .= "<ul class=\"json-object-list\">";
            
            foreach ($jsonObject as $jsonKey => $jsonValue) {
                $returnValue .= "<li>";
                
                $returnValue .= "<div class=\"widget-jsonobject-key\">" . _dh($jsonKey) . ":</div>";
                $returnValue .= "<div><input class=\"widget-jsonobject-value\" type=\"text\" disabled=\"disabled\" value=\"${jsonValue}\" /></</div>";
                
                $returnValue .= "</li>";
            }
            
            $returnValue .= "</ul>\n";
        }
        
        return $returnValue;
    }
875675
public function javascript()
    {
        $scriptContent = file_get_contents($this->pagseguro->getUrl()['javascript']);

        return response()->make($scriptContent, '200')
            ->header('Content-Type', 'text/javascript');
    }
1045853
public function handler(): Response
    {
        if ($this->redirect) {
            return response(null, 302, ['Location' => $this->redirect]);
        } elseif ($this->request->query->has('error')) {
            return view('error.twig', [
                'error' => $this->request->query->get('error'),
                'message' => $this->request->query->get('message')
            ]);
        } else {
            $this->addAssets();
            return view($this->template, $this->data);
        }
    }
733551
public function index()
	{
		$posts = $this->posts->active(100);

		$data = array(
			'posts'   => $posts,
			'updated' => isset($posts[0]) ? $posts[0]->atom_date : date('Y-m-d H:i:s'),
		);

		return Response::view($this->theme.'.atom', $data, 200, array(
			'Content-Type' => 'application/rss+xml; charset=UTF-8',
		));
	}
274071
public function handler(): Response
    {
        $response = [];
        foreach (Role::all(['createdAt' => 'ASC']) as $role) {
            $response[] = [
                'id' => $role->getId(),
                'name' => $role->getName(),
                'slug' => $role->getSlug(),
                'color' => $role->getColor(),
                'icon' => $role->getIcon()
            ];
        }
        return response($response);
    }
293091
public function ajaxSubmit()
    {
        $this->_add($cb = new jsCallback(), ['desired_name' => 'submit', 'postTrigger' => true]);

        $this->add(new View(['element' => 'input']))
            ->setAttr('name', $cb->postTrigger)
            ->setAttr('value', 'submit')
            ->setStyle(['display' => 'none']);

        $cb->set(function () {
            $caught = function ($e, $useWindow) {
                $html = '<div class="header"> '.
                        htmlspecialchars(get_class($e)).
                        ' </div> <div class="content"> '.
                        ($e instanceof \atk4\core\Exception ? $e->getHTML() : nl2br(htmlspecialchars($e->getMessage()))).
                        ' </div>';
                $this->app->terminate(json_encode(['success' => false, 'message' => $html, 'useWindow' => $useWindow]));
            };

            try {
                $this->loadPOST();
                ob_start();
                $response = $this->hook('submit');
                $output = ob_get_clean();

                if ($output) {
                    $message = new Message('Direct Output Detected');
                    $message->init();
                    $message->addClass('error');
                    $message->text->set($output);

                    return $message;
                }

                if (!$response) {
                    if (!$this->model instanceof \atk4\ui\misc\ProxyModel) {
                        $this->model->save();

                        return $this->success('Form data has been saved');
                    }

                    return new jsExpression('console.log([])', ['Form submission is not handled']);
                }
            } catch (\atk4\data\ValidationException $val) {
                $response = [];
                foreach ($val->errors as $field => $error) {
                    $response[] = $this->error($field, $error);
                }

                return $response;
            } catch (\Error $e) {
                return $caught($e, false);
            } catch (\Exception $e) {
                return $caught($e, true);
            }

            return $response;
        });

        //var_dump($cb->getURL());
        $this->js(true)
            ->api(array_merge(['url' => $cb->getJSURL(), 'method' => 'POST', 'serializeForm' => true], $this->apiConfig))
            ->form(array_merge(['inline' => true, 'on' => 'blur'], $this->formConfig));

        $this->on('change', 'input', $this->js()->form('remove prompt', new jsExpression('$(this).attr("name")')));
    }
1102889
public function seeResponseIsJson()
    {
        $responseContent = $this->connectionModule->_getResponseContent();
        \PHPUnit\Framework\Assert::assertNotEquals('', $responseContent, 'response is empty');
        json_decode($responseContent);
        $errorCode = json_last_error();
        $errorMessage = json_last_error_msg();
        \PHPUnit\Framework\Assert::assertEquals(
            JSON_ERROR_NONE,
            $errorCode,
            sprintf(
                "Invalid json: %s. System message: %s.",
                $responseContent,
                $errorMessage
            )
        );
    }
1082191
protected function RenderImpl()
    {

        $url = $this->owner->getURLNode() . "::" . $this->id . "&ajax=true";
        if ($this->refresh) {
            $this->setAttribute("onclick", "getUpdate('{$url}');event.returnValue=false; return false;");
        }
        $this->setAttribute('src', $this->owner->getURLNode() . "::" . $this->id . ':' . time() . '&binary=true');
    }
511441
public function index(): JsonResponse
    {
        $config = $this->makeView('language-view', trans('HCCore::languages.title.list'))
            ->addFormSource('add-new', 'language')
            ->addDataTable($this->getDataTable())
            ->setPermissions(['search'])
            ->toArray();

        return $this->response->success('OK', $config);
    }
791551
protected function ajaxResponseHandler()
    {
        echo json_encode([
            'success'      => $this->errorMessage ? 0 : 1,
            'errorMessage' => $this->errorMessage,
            'errorCode'    => $this->errorCode,
            'data'         => $this->errorMessage ? '' : $this->dataPacket,
        ]);

        die();
    }
711164
public function render()
    {
        // Set the request arguments as GET parameters
        $_GET = $this->getRequestArguments();

        try {
            /** @var \TYPO3\CMS\Extbase\Mvc\Web\Response $response */
            $response = $this->objectManager->get(Response::class);
            $this->request->setOriginalRequestMappingResults($this->validationErrors);
            $this->getControllerInstance()->processRequest($this->request, $response);
            $result = $this->beautify($response->getContent());

            // In case of an error
        } catch (\Exception $e) {
            $result = '<pre class="error"><strong>'.$e->getMessage().'</strong>'.PHP_EOL
                      .$e->getTraceAsString().'</pre>';
        }

        return $result;
    }
625073
public function indexAction()
    {
        if ($this->getRequest()->isAjax()) {
            try {
                $this->loadLayout(null, false, false);
                $this->getLayout()->getUpdate()->setCacheId(null);
                $this->getLayout()->getUpdate()->addHandle(strtolower($this->getFullActionName()) . '_AJAX');
            } catch (Exception $e) {
                Mage::logException($e);
                $this->getResponse()->setHeader('Content-Type', 'application/json');
                $this->getResponse()->setBody(Zend_Json::encode(['error' => true, 'message' => $e->getMessage()]));
            }
        }

        $this->loadLayout();
        $this->renderLayout();
    }