DELETE, with [ajax] modifier not working?

Skip to first unread message

Benque Verkoop op Rekening

Jun 24, 2022, 10:22:33 AM6/24/22
to Fat-Free Framework
Hi Guys,

in my routes i stuck to DELETE verb for cruD actions. I created a javascript function doing a fetch() sending the DELETE method. That works fine. However I would like to try out the route modifiers [sync] and [ajax] but that does not work.

When this route is requested i get a '405 - method not allowed'

DELETE /omnia/@model/@item [ajax] = Controllers\Omnia\Crud->destroy

when i omit the [ajax] it works. This route is fine.

DELETE /omnia/@model/@item = Controllers\Omnia\Crud->destroy

The routes are stored in an ini file. Any idea why this doesn't work? The documentation does not provide clear guidelines on combining DELETE and [ajax]. Only GET and POST are specifically mentioned.



Jun 25, 2022, 2:02:14 AM6/25/22
to Fat-Free Framework

F3's Ajax detection depends on the presence of the following header:

X-Requested-With: 'XMLHttpRequest'

Apparently fetch() doesn't send that header by default so you'll have to add it manually on your fetch request.

More info:


Benque Verkoop op Rekening

Jul 8, 2022, 5:48:19 AM7/8/22
to Fat-Free Framework
Aha, thx.

Added headers line below and now it works!

fetch(route, {
   method: 'DELETE',
   headers: new Headers({ 'X-Requested-With': 'XMLHttpRequest' })

Op zaterdag 25 juni 2022 om 08:02:14 UTC+2 schreef ved:
Reply all
Reply to author
0 new messages