【发布时间】:2014-09-17 21:53:20
【问题描述】:
我的问题是后端服务器(用 grails 编写)会自动将我的请求 URL 转换为不同的 URL。具体来说,它将它从 /UXChallengeAwards/processSelectedNotifications 更改为 /UXChallengeAwards/index。
--
在模板 gsp 文件中,我定义了一个按钮,当点击时会进行 jQuery ajax 调用:
<button class="blue-link"
onclick="jQuery.ajax({type:'POST',
data:jQuery(this).parents('.multiSelectForm').serialize(),
url: '/ici/UXChallengeAwards/processSelectedNotifications/${challenge.id}',
success:function(data,textStatus){},
error:function(xhr,textStatus,errorThrown){}
})" >
UXChallengeAwardsController.processSelectedNotifications 方法存在。它执行一些工作,然后重定向到控制器中的另一个操作。事实上,这曾经奏效。但不知何故,在添加第二个按钮的过程中,我做了一个似乎破坏了事情的改变。
现在单击按钮时,请求 URL 将切换到 /ici/UXChallengeAwards/index 并返回 404,因为 index 在此控制器中不作为操作存在。
我用谷歌搜索过,当这种情况发生时,最常见的答案是控制器必须为视图返回一些结果。但是我在控制器中看到了很多重定向的例子,我看不出我做错了什么。 (我确实尝试了渲染结果的变体,但没有成功。)
这是我的控制器操作的样子:
def processSelectedNotifications = {
def challenge
def checkboxes = params.list('selectCheckbox');
for (checkbox in checkboxes) {
// the checkbox contains the id of a ChallangeAward that should be published
ChallengeAwards challengeAwards = ChallengeAwards.get(checkbox.toInteger())
if (challengeAwards) {
// grab a challenge for use in the redirect, they are all the same
challenge=challengeAwards.challenge
publish(challengeAwards)
}
}
if (challenge) {
redirect action: 'challengeAwardsRemote', id: challenge.id
return
}
// render a failure message if we got here
render messageNS(code:"UX.ChallengeAwards.Publish.failure")
}
对于可能出现的问题或如何解决此问题的任何见解,我将不胜感激。我检查了我的 UrlMappings,这是应该处理这个控制器/方法请求的规则:
"/$controller/$action?/$id?"{ constraints {} }
非常感谢!
【问题讨论】:
标签: grails-2.0