1
votes

This is my jQuery code which I am using to make an Ajax Request:

$(".rowClick tr").click(function()
                {
                    var id = $(this).data("id");

                    $.ajaxSetup({
                        headers: {
                            'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                        }
                    });

                    $.ajax({
                        url: 'example/',
                        type: 'POST',
                        data: {id: id},
                    })
                    .done(function() {
                        console.log("success");
                    });
                })

This is the Route Code I have written:

Route::get('example/','example@exampleDetailController');

Whenever I am making an ajax request to post on this URL it gives me a 405 (Method Not Allowed).

Why is this error occurring?

1
Maybe try type: 'GET',brennan

1 Answers

2
votes

Because your Ajax request is submitting as a POST but you're registering the route as a GET.

Change it to:

Route::post('example/','example@exampleDetailController');

You can read more about routing and the other methods: https://laravel.com/docs/5.5/routing