Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

217
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!