Fetch does not work not correctly with symfony

// when i click on the link ‘a’ ,the alert works but the fetch method does not work

main.js

const articles = document.getElementById('format');

if (articles) {

  articles.addEventListener('click', e => {
    if (e.target.className === 'btn btn-danger') {
      if (confirm('Are you sure?')) {
        const id = e.target.getAttribute('data-id');
        console.log(id);
        fetch(`/thema/delete/${id}`, {
          method: 'DELETE'
          
         
        }).then(console.log("dsdasdasdsa"));
      }
    }
  });
}

// admin controller

     * @Route("/thema/delete/{id}" , name="thema")
     * @Method({"DELETE"})
     */
    public function delete(Request $request, $id) 
      {

        dump(
            "dsadsadsda"
        );
        die();
      }

// twig template

<a href="" class="btn btn-danger" data-id="{{k.id}}">
          Delete
          </a>

what iam doing wrong ??
i can not fetch the Method delete in adminController !
the message should be dumped .

Source: Symfony Questions

Was this helpful?

0 / 0

Leave a Reply 0

Your email address will not be published. Required fields are marked *