Foued MOUSSI
Foued MOUSSI

Reputation: 4813

Laravel 5 : Retrieve sent POST data through ajax

I try to submit a laravel form exactly like this example :

https://gist.github.com/davestewart/1db1c4b56a85fc46e1f8.

$.post('/ajax/post', {payload:'hello'}, onSuccess);

When i try to get access the payload string 'hello' using :

$request->get('payload');

I get null.

Upvotes: 1

Views: 210

Answers (2)

Zakaria Acharki
Zakaria Acharki

Reputation: 67525

Try to get it using input :

$request->input('payload');

And you could first check the developpers console under network tab to make sure that the variable is sent by the post request.

And you could always check the attributes of the request using :

dd($request);

Hope this helps.

Upvotes: 1

Rastagar
Rastagar

Reputation: 183

Test Your variable inside your javascrip

// handlers
        function onGetClick(event)
        {
            // we're not passing any data with the get route, though you can if you want
         console.log(get your variable)
            $.get('/ajax/get', onSuccess);
        }

Maybe your variable has no data

Upvotes: 0

Related Questions