0

I have to pass parameters per post with ajax but not working on the console I get this:

POST http://localhost:8000/prueba2 405 (Method Not Allowed)

This is my routing:

Route::get('prueba2', 'HomeController@index');

This is my ajax:

$.ajax({
    url: '{{url('prueba2')}}',
    type: 'POST', // Send post data
    data: 'type=fetch',
    async: false,
    success: function(s){
        json_events = s;
    }
});

This is my controller:

public function index(){

    return 'hola';
}

All this is a test and is not the final driver nor the final ajax, but it seems to be some response by the controller. But unfortunately I get a 405.
If someone can help me with this serious problem it would be a lot of help

zx485
  • 28,498
  • 28
  • 50
  • 59
Tprogramer
  • 85
  • 1
  • 14

1 Answers1

1

You are receiving a MethodNotAllowedException because you defined a GET route with Route::get('prueba2', 'HomeController@index');, but you do a POST request.

Change your AJAX type to GET or use Route::post().

The last one would look like:

Route::post('prueba2', 'HomeController@index');
manniL
  • 7,157
  • 7
  • 46
  • 72
  • Thank you so much for your help – Tprogramer Dec 01 '16 at 19:11
  • One question, do you know what this error means?: Uncaught SyntaxError: Unexpected token H in JSON at position 0 @manniL – Tprogramer Dec 01 '16 at 19:14
  • I'm certainly not sure, but you can may refer to http://stackoverflow.com/questions/37280274/syntaxerror-unexpected-token-in-json-at-position-0-in-react-app – manniL Dec 01 '16 at 19:22