0
我送了以下AJAX请求:如何从Grails中的AJAX错误回调中检索错误消息?
$.ajax({ type: 'POST',
data: $(this).parents('form:first').serialize(), url:'/myapp/comment/saveOrUpdate',
success: function(data,textStatus) {insertNewComment(data)},
error: function(xhr, textStatus, errorThrown) {alert(xhr.responseText);}
})
...和我控制器操作是这样的:
class CommentController {
...
def saveOrUpdate = {
...
if (error) {
response.sendError 419, 'You must wait at least 5 minutes before posting a new comment'
}
}}
不幸的是,我从来没有看到我在HTTP响应发送消息。相反,我从Tomcat /阿帕奇(或Grails的?)产生错误的HTML页面,看起来像:
<html><head><title>Apache Tomcat/6.0-snapshot - Error report</title>
</head><body><h1>HTTP Status 419 - </h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u></u></p><p><b>description</b> <u>Cannot find message associated with key http.419</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/6.0-snapshot</h3></body></html>
我怎样才能绕过产生的错误HTML页面,以便从JavaScript代码的消息“您检索必须等待......'?
谢谢你的帮助。
我已经按照您的建议实施了应用程序级别的状态代码。 谢谢。 – fabien7474 2010-08-25 10:40:01