【发布时间】:2015-08-27 04:31:09
【问题描述】:
我有一个控制器,它返回一些对象,在不好的情况下,它应该将错误消息传输到 ajax 中的错误部分。 responseText 不接受,因为 tomcat 返回给我一个带有标签和完整堆栈跟踪的整个页面,但我只需要几句话就可以向用户显示此消息。
@RequestMapping(value = {"/charts"}, method = RequestMethod.POST)
@ResponseBody
public Chart handleSelectionFiled(@RequestBody Chart chart) {
try{
chart.doSmth();
} catch (Exception e) {
//some code to transmit exception message - this is my question
}
return chart;
}
ajax函数
$.ajax({
contentType: 'application/json',
mimeType: 'application/json',
type: frm.attr('method'),
url: frm.attr('action'),
dataType: 'json',
data: data["chosenFile"],
success: function (response) {
turnOffPreLoader($("#defects_info"),response);
$('#selectionForm').submit();
},
error: function (jqXHR, textStatus, errorThrown) {
$("#result").text(errorThrown);
turnOffPreLoader($("#defects_info"),"default:50");
}
});
【问题讨论】:
标签: java javascript ajax spring servlets