Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Randy_Johnson's avatar

InertiaJS unwanted data

On the page I have a form and when a select box is used I want it to grab data from the database without refreshing the page, or presenting the data as it is doing now in a json output box covering the entire browser window.

I know this can be done in Axios, but I was thinking I would prefer to just try and stick to inertia functions.

        router.get(
            `/teacher/buildings/1`,
            {
                preserveScroll: true,
                only: ['buildings'],
                onSuccess: () => {
                    return Promise.all([
                        setShow(false),
                    ])
                },
                onError: () => {
                    return Promise.all([
                    ])
                }
            });
    public function show($id)
    {
        $buildings = Building::where('school_id', $id)->get();
        return response()->json($buildings);
    }
0 likes
1 reply
gych's avatar
gych
Best Answer
Level 29

You can't use router.get to return json, when you use this it unmounts the current rendered template. Either return and re-render the template with the requested data as prop or use axios to only return json.

Please or to participate in this conversation.