【发布时间】:2010-08-05 22:03:23
【问题描述】:
我正在发送以下 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/Apache(或 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 代码中检索消息“您必须等待...”?
感谢您的帮助。
【问题讨论】:
标签: jquery ajax grails error-handling http-status-codes