Hide
Hide

Reputation: 3317

fetch with DELETE method doesnt' work

I made API server with DRF so if delete the data, I have to use DELETE method.

So I tried to request to server with method: 'DELETE', But it doesn't work.

[js file]

    fetch("http://abc/article/24",
    {
        method: "DELETE",
        headers: {
            'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
        },
        body: JSON.stringify({password: '123'})
    })

I captured packet with Chrome Network tab, It's Request Header is OPTION.

In my code, I defined method to DELETE. But why Request Header's METHOD is OPTION?

[ADDED SCREENSHOT]

enter image description here

enter image description here

I set the response code if success, return 204, fail return 304

Upvotes: 5

Views: 13307

Answers (1)

Hide
Hide

Reputation: 3317

[SOLVED]

Solved by Content-Type: 'application/json' and payload into http body.

That works perfectly.

Upvotes: 4

Related Questions