【发布时间】:2014-11-25 18:15:21
【问题描述】:
我正在使用数据表版本 1.10.0 来提供搜索功能。
我想知道服务器端处理如何操作响应。 例如,我有一个 json 响应,它返回要显示的记录和状态。
我的要求是,如果服务器端验证失败,我不想绘制表格,而是在屏幕上呈现错误消息。否则绘制表格。
下面的简单示例:
$('#result').dataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "search",
"type": "POST",
//"dataSrc": "resultList",
"dataSrc": function ( json ) {
if (json.responseStatus.value == 'Validation Failure') {
//show error messages on screen
//prevent redraw
} else {
//draw the table with the resultList
}
}
"columns": [
{ "data": "referenceNumber"},
{ "data": "fileName" },
{ "data": "documentType" },
{ "data": "uploadType" },
{ "data": "createdBy" },
{ "data": "memberName" },
{ "data": "dateOfBirthStr"},
{ "data": "createdDateStr" },
{ "data": "comment" },
{ "data": "status" }
]
} );
更新: 在服务器端我返回 403:
return new ResponseEntity(searchUploadResponse, HttpStatus.FORBIDDEN);
在客户端:
$('#result').dataTable( {
"processing": true,
"serverSide": true,
"ajax": {
"url": "search",
"type": "POST",
"dataSrc": "resultList",
error: function (jqXHR, textStatus, errorThrown) {
//handle errorThrown in here
alert("error" + jqXHR + " : " + textStatus + " : " + errorThrown);
}
} ,
结果是我可以显示我的错误消息。 datatables 使用“处理” div 阻止对表的访问。
【问题讨论】: