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