简体   繁体   English

使用 javascript 发送删除请求

[英]Send delete request with javascript

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.所以在 url 中他只会发送物品的 ID。

So simply a javascript call like this would be fine.所以像这样简单的 javascript 调用就可以了。

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

But of course this would be a GET request and not a delete.但当然这将是一个 GET 请求而不是删除。 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.只需在服务器端将其声明为 GET 请求,或者我不想将其设为 ajax 调用。

There is no other way than using an ajax request.除了使用 ajax 请求之外,别无他法。 With jquery it looks like that:使用 jquery 它看起来像这样:

$.ajax({
     url : 'myurl',
     method : 'delete',
     data : {
        itemid :id
     }
})

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM