简体   繁体   English

DELETE 请求在重定向时不会更改为 GET

[英]DELETE request is not changing to GET on redirect

I am sending DELETE type Ajax request to my delete method in my controller.我正在向控制器中的删除方法发送DELETE类型的 Ajax 请求。 For successful delete, I am trying to redirect to another method in same controller that reloads the list and is of GET type.为了成功删除,我试图重定向到同一控制器中的另一个方法,该方法重新加载列表并且是GET类型。

Currently my delete operation is working fine with default status code 302,but on redirect, it is redirecting with 'Request Method: DELETE' instead of 'GET' which is default behavior of Grails .目前我的删除操作在默认状态代码 302 下工作正常,但在重定向时,它使用'Request Method: DELETE' instead of 'GET'进行重定向,这是Grails 的默认行为。

Kindly suggest the solution for it请提出解决方案

redirect(action: 'list',controller:'dashboard')

If you want to do a redirect you should be doing an http call rather than an Ajax call.如果您想进行重定向,您应该进行 http 调用而不是 Ajax 调用。 The redirect is handled automatically by your browser so you can't change it from a delete to a get.重定向由您的浏览器自动处理,因此您无法将其从删除更改为获取。 You might try using a forward or making a separate call to the list in a callback/promise.您可以尝试在回调/承诺中使用转发或单独调用列表。

Alternatively if you want to keep it in one Ajax call, I would hope that your dashboard controller, list action would be calling a service to get it's data.或者,如果您想将其保留在一次 Ajax 调用中,我希望您的仪表板控制器、列表操作将调用一项服务以获取其数据。 So instead of doing a redirect I would call that services, and return that data.因此,我将调用该服务并返回该数据,而不是进行重定向。

I say hope because I've seen many examples, where people put business logic in controllers, where it doesn't belong, instead of moving it to a service, where it can be reused.我说希望是因为我看过很多例子,人们将业务逻辑放在控制器中,它不属于它的地方,而不是将它移到可以重用的服务中。

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

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