2

I have a client server application. The user should be able to delete an item. So in the url he will just send the ID of the item.

So simply a javascript call like this would be fine.

window.location = '/api/games?ItemId'=id ; 

But of course this would be a GET request and not a delete . So what should I do now.

Just declare it a GET Request on server side or what I do not want to do make it an ajax call.

3
  • with the get request, you can then activate php and run the delete function right? something like this: if (isset($_GET['id'])) { $id = $_GET['id']; $remove->removeImage($id); } and if php code in that file is not possible or wanted, you might have to use ajax to send it to a php handler file Commented Oct 11, 2019 at 14:27
  • 1
    Browsers are were designed to be just that ... browsers. i.e they handle GET requests. Then someone thought it would be handy to able to send some data and along came <form> which uses the existing HTTP verb POST. There's no general way in a browser to send a DELETE verb without using javascript. Commented Oct 11, 2019 at 14:34
  • If you're using HTML without javascript, then you would POST a <form> (to a POST handler) as a work-around. Then a few years ago someone realised that we should be using the correct verb for the correct action instead of piggy-backing on existing verbs, but there's still no built-in way to send PUT and DELETE requests. Commented Oct 11, 2019 at 14:37

1 Answer 1

2

There is no other way than using an ajax request. With jquery it looks like that :

$.ajax({ url : 'myurl', method : 'delete', data : { itemid :id } }) 
Sign up to request clarification or add additional context in comments.

8 Comments

yep my mystake @RoryMcCrossan I did not see the op asked not to use AJAX and i made a mistake in the data
There are other ways... fetch
wich one @epascarello ? I'm genuinely intrigued by that !
Unfortunately not. The sooner IE fades in to obscurity the better :)
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.