Route :: post does not work correctly in Laravel

Question:

The rule was created:

Route::post('/signup', 'AuthController@signup');

When trying to send a POST request from Ajax, the following problem takes off:

Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException

I didn't find anything interesting, except how to put route="прим" on the form, which will be of no use to me, since the form is sent by an ajax request, using the POST method, as expected.

UPD: version 4.2.

Controller code:

class AuthController extends BaseController {

    public function signup () {
        return Response::json(array('data' => $_POST));
    }

}

With filled fields:

GET Data
empty
POST Data
username    test
email   
password    test
confirm test
submit

In the js console:

test.app
POST    405
Method Not Allowed
text/html

JS code in studio: D

$(function() {
    $('#signup').submit(function(e){
        e.preventDefault();

        var username = $('#username').val();
        var email = $('#email').val();
        var password = $('#password').val();
        var confirm = $('#confirm').val();

        $.ajax({
            type: 'post',
            url: '//test.app/signup',
            dataType: 'json',
            data: {
                username = username,
                email = email,
                password = password,
                confirm = confirm
            },
            success: function (response) {
                console.log(response);
            }
        });

    });
});

Answer:

I suspect that some other handler is triggered for you and sends a POST to the index, and in the routes the index only supports GET – hence the error

And the code that you provided contains an error and is not used anywhere at all ( or did I miss the point and JS now accepts = ? ):

...
  data: {
    username = username,
    email = email,
    password = password,
    confirm = confirm
  }
...
Scroll to Top