The rule was created:

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

When you try to send a POST request from Ajax, this problem crashes:

 Symfony \ Component \ HttpKernel \ Exception \ MethodNotAllowedHttpException 

I didn’t find anything interesting, except how to put route="прим" on the form, which isn’t enough for me, since the form is sent to the 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)); } } 

When fields are filled:

 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 the 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); } }); }); }); 
  • JS code in the studio - avengerweb
  • @avengerweb in the studio: D - Bastiane
  • Is this route present in php artisan routes ? - user13856
  • @ slider23 is by itself present. + -------- + ------------- + ------ + ------------------- --------- + ---------------- + --------------- + | Domain | URI | Name | Action | Before Filters | After Filters | + -------- + ------------- + ------ + ------------------- --------- + ---------------- + --------------- + | | GET | HEAD / | | HomeController @ showWelcome | | | | | POST signup | | AuthController @ signup | | | + -------- + ------------- + ------ + ------------------- --------- + ---------------- + --------------- + - Bastiane

4 answers 4

I suspect that some other handler works for you and sends POST to the index, and in the routes the index only supports GET - hence the error

And the code you gave contains an error and is not used anywhere at all ( or have I missed the moment and now JS perceives = ? ):

 ... data: { username = username, email = email, password = password, confirm = confirm } ... 
  • And I would answer damn :). But this JS code works for me. And yes, I wrote it down as it should, if it makes it easier for you to have data: {username: username, email: email, password: password, confirm: confirm}, but the problem described in the question did not dare! - Bastiane
  • Yes of course. And the request goes to test.app/ajaxsignup ? - xEdelweiss
  • Now conduct an experiment and remove this code to hell. Nothing will change. Then think again about where the problem is in my answer. - xEdelweiss
  • The request goes where it should be. url: '{{URL :: action (' AuthController @ signup ')}}' - Bastiane
  • My reserve of patience has run out. - xEdelweiss

@Bastian, try, please, with the POST form, send some Input and upload a screenshot of the error. Interested specifically in Whoops'e columns "Get data" & "Post data". To understand what I want, I attach a screenshot:

=)

    Remove the leading slash and show the controller method, please.

    Update

    This is to warm up and to find out what the version of Laravel is. :)

    As it seems to me, the problem is that the get request is sent to the post method. Therefore, I want to check both the controller method and the request in the browser console.

    • Well, don't scare people, my L4.2 works with a leading slash :) - Quiss
    • This is for warming up and to find out what the version of Laravel is. :) It seems to me that the problem is that the get request is sent to the post method. Therefore, I want to check both the controller method and the request in the browser console. - smgladkovskiy

    Just noticed:

     test.app POST 405 Method Not Allowed text/html 

    Why isn't the URL test.app/ajaxsignup ?

    • Probably because the request to test.app/ajaxsignup is made in ajax. - Bastiane
    • @Bastian, this is not the reason. - xEdelweiss
    • @xEdelweiss then where is she, the reason is this? - Bastiane
    • @Bastian, I added an answer. - xEdelweiss