Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

216
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda