Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

sergionc's avatar

delete record with fetch api

I am trying to delete a record using fetch api but I get the following error: The GET method is not supported for this route. Supported methods: DELETE.

button:

                        <button class="btn btn-danger btn-sm"
                            onclick="deletePersona({{$persona->id}})">
                            <i class="fas fa-times">
                            </i>
                        </button>

Code js:

function deletePersona(id) { fetch("/persona_eliminar/" + id, { method: "DELETE", }) .then((res) => res.json()) .then((response) => { console.log(response); }); }

0 likes
3 replies
sergionc's avatar

It works fine, I usually delete a record like this:

              <form action="{{route('persona.destroy', $persona->id)}}"
                            class="d-inline" method="post">
                            @csrf
                            @method('delete')
                            <button class="btn btn-danger btn-sm btnhola" type="submit">
                                <i class="fas fa-times">
                                </i>
                            </button>
                        </form>

Now I want to do it through fetch api js vanilla.

Crash's avatar

Can you put your route here, please? can you remove all the other routes from the same path and try again?

Please or to participate in this conversation.