Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

214
Visualizações
How can I grab the response of only the 2nd parameter of the view() function when doing a GET request?

I'm doing an ajax GET request

$(dataTableSearchInputButtonID).on('click', function () {
            $.ajax({
                type: "GET",
                url: "myUrl.test/tools",
                dataType: "html",
                success: function (resp) {
                    console.log(resp);
                },
            });
        });

However, in the response in the console, I'm only seeing the HTML upon clicking the Search button (to retrieve and display data)

public function getTriviaTags(Request $request){
    try {
        $userSearch = $request->get('userSearch');
        $tagsList = $this->tagRepository->getTags($userSearch);

        $response = [
            'tagsList' => $tagsList,
            'userSearch' => $userSearch,
            'trivia' => 'tag'
        ];

        return view('pages.tools.main', $response);
    } catch (Exception $exception) {
        parent::log($exception, self::class);
    }
}

How can I make sure that the $response variable appears (console.log(resp);) in the ajax success() method upon inputing text on the input field and click Search?

I need to append userSearch to the URL (myUrl.test/tools?userSearch="countries") so that the correct data appears. When I do it manually, in the search bar, it works fine.

Am I on the right track of achieving this?

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

You should not return view, but JSON response:

public function getTriviaTags(Request $request){
try {
    $userSearch = $request->get('userSearch');
    $tagsList = $this->tagRepository->getTags($userSearch);

    $response = [
        'tagsList' => $tagsList,
        'userSearch' => $userSearch,
        'trivia' => 'tag'
    ];

    return response()->json($response)
} catch (Exception $exception) {
    parent::log($exception, self::class);
}

}

And then you can access response variables via console.log(resp.data)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda