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

ellisee22's avatar

Dump not showing after AJAX Request

Hi y'all, my name is Elli and I'm new to this forum. I tried out Ajax for the first time now in my life. I want to send a value from a selection-list via AJAX to my controller, because I dont want to reload the website. The problem is, that there is no dump coming, after I typed dd($request). I want to see the data, that is coming in for further editing.

But the Jquery-Script is returning "success".

So I think the request is not reaching the controller. I tried for serveral hours finding a solution but I cant get it. Maybe someone here knows whats going on.

tableselection.blade.php: 

<body>
<form id="search-form">
    <div id="search-form-filters" data-filters-count="1">
        <div class="filter">
            <select id="select-options">
                <option value="customer">Kunden</option>
                <option value="contact_person">Ansprechpartner</option>
            </select>
        </div>
    </div>
    <button class="submit-button" type="submit">Suchen</button>
</form>

<script type="text/javascript">
    $.ajaxSetup({
        headers: {
            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
        }
    });

    $('#search-form').on('submit', function(event){
        event.preventDefault();

        table = $('#select-options').val();

        $.ajax({
            url: '/search-form',
            type: "POST",
            data:{
                table: table,
            },
            success:function(response){
                if (response) {
                    console.log("success");
                    $("#search-form")[0].reset();
                }
            },
            error: function() {
                console.log("failure");
            }

        });
    });
</script>
</body>
web.php

<?php

Route::get('/',function () {return view('tableselection');});

Route::post('/search-form', [TableSelectionController::class,'gatherData']);

?>
TableSelectionController:

    public function gatherData(Request $request)
    {
        dd(json_encode($request));
      
    }

After trying the devtools out, I got this in preview: "{"attributes":{},"request":{},"query":{},"server":{},"files":{},"cookies":{},"headers":{}}"

I got a 200 and this was the preview. Headers tab contained formdata : table: customer

0 likes
2 replies
tykus's avatar
tykus
Best Answer
Level 104

Install the laravel-dump-server package

https://github.com/beyondcode/laravel-dump-server

composer require --dev beyondcode/laravel-dump-server

You can run the dump-server in your terminal and see the result of dump and dd in the terminal whenever making AJAX requests.

php artisan dump-server
2 likes
ellisee22's avatar

Thank you so much, its working now! Yesterday I tried to do this but it kept throwing errors, I should extend my php.ini with ext-http *. Turns out, you need to remove that line from you composer.json.

Please or to participate in this conversation.