Is there some way I can show custom exception messages as an alert in my jQuery AJAX error message?
(有没有什么方法可以在我的jQuery AJAX错误消息中显示自定义异常消息作为警报?)
For example, if I want to throw an exception on the server side via Struts by throw new ApplicationException("User name already exists");
(例如,如果我想通过扔在服务器端异常的Struts通过throw new ApplicationException("User name already exists");
)
(,我想在jQuery AJAX错误消息中捕获此消息('用户名已存在')。)
jQuery("#save").click(function () {
if (jQuery('#form').jVal()) {
jQuery.ajax({
type: "POST",
url: "saveuser.do",
dataType: "html",
data: "userId=" + encodeURIComponent(trim(document.forms[0].userId.value)),
success: function (response) {
jQuery("#usergrid").trigger("reloadGrid");
clear();
alert("Details saved successfully!!!");
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
alert(thrownError);
}
});
}
});
On the second alert, where I alert the thrown error, I am getting undefined
and the status code is 500.
(在第二个警报,我警告抛出的错误,我得到undefined
,状态代码是500。)
I am not sure where I am going wrong.
(我不确定我哪里出错了。)
What can I do to fix this problem?(我该怎么做才能解决这个问题?)
ask by translate from so