标签:
服务端返回json类型数据,解析问题
服务端MIME使用text/html 类型 返回普通json字符串;
jquery.dtgrid.js : line :240 在ajax的success回调函数中第一句加入验证
$.ajax({ type:‘post‘, url:url, data:params, contentType: "application/x-www-form-urlencoded; charset=utf-8", beforeSend: function(xhr) {xhr.setRequestHeader("__REQUEST_TYPE", "AJAX_REQUEST");}, success:function(pager){ if(typeof pager === "string"){ pager = $.parseJSON(pager); } //如果出错表示有可能是程序问题或高级查询方案配置有误 if(!pager.isSuccess){ $.fn.DtGrid.tools.toast($.fn.DtGrid.lang[dtGridReflectionObj.option.lang].errors.ajaxLoadError, ‘error‘, 5000); dtGridReflectionObj.hideProcessBar(); return; }
服务端view构建,
public class DTGridView { /** * 用途:高级查询的查询参数合集,将由组件根据用户选择自行生成。<br/> */ private List<String> advanceQueryConditions; /** * 用途:高级查询的排序参数合集,将由组件根据用户选择自行生成。<br/> */ private List<String> advanceQuerySorts; /** * 用途:是否导出全部数据,将由组件根据用户选择自行处理。<br/> */ private boolean exportAllData = false; /** * 用途:导出的列集合,将由组件根据用户选择自行处理。<br/> */ private List<String> exportColumns; /** * 用途:导出的数据是否已经被处理。<br/> * 该属性为前后台的一个数据处理标识,经由resolution、数据格式化等操作完成处理的数据被视为已处理。<br/> */ private boolean exportDataIsProcessed; /** * 用途:高级查询的查询参数合集,将由组件根据用户选择自行生成。<br/> */ private String exportFileName; /** * 用途:导出的文件类型,将由组件根据用户选择自行处理。<br/> */ private String exportType; /** * 用途:展示的数据结果集。<br/> */ private List<Map<String, Object>> exhibitDatas; /** * 用途:导出的数据集合,将由组件根据用户选择自行生成,生成的导出数据均为处理后的数据。<br/> */ private List<Map<String, Object>> exportDatas; /** * 用途:快速查询的参数合集,将由组件根据用户选择自行生成。<br/> */ private Map<String, Object> fastQueryParameters; /** * 用途:用于判断前台的交互信息是否为导出的动作。<br/> */ private boolean isExport; /** * 用途:数据是否加载成功,若查询SQL出现错误或高级查询中配置错误,则该返回值为false,正确查询则为true。<br/> */ private boolean isSuccess; /** * 用途:当前页号。<br/> * 特殊说明:该参数可以手动修改。 */ private int nowPage; /** * 用途:当前查询的纪录总页数。 <br/> */ private int pageCount; /** * 用途:每页的显示的记录条数。<br/> */ private int pageSize; /** * 用途:自定义参数集合。该参数可通过Javascript手动设置,属性类型为Object对象。<br/> * 可以通过Javascript设置参数,设置完成后通过服务器端封装的Pager对象访问对象中的parameters属性即可获得对应参数集合,<br/> * 该集合对应Java服务器为Map对象。 */ private Map<String, Object> parameters; /** * 用途:当前查询的纪录总数。<br/> */ private int recordCount; /** * 用途:开始的记录号。<br/> */ private int startRecord; /** * 默认初始化数据 */ public DTGridView() { this.advanceQueryConditions = Lists.newArrayList(); this.advanceQuerySorts = Lists.newArrayList(); this.exportAllData = false; this.exportColumns = Lists.newArrayList(); this.exportDataIsProcessed = false; this.exportFileName = "exportfilename"; this.exportType = ""; this.exhibitDatas = Lists.newArrayList(); this.exportDatas = Lists.newArrayList(); this.fastQueryParameters = Maps.newHashMap(); this.isExport = false; this.isSuccess = false; this.nowPage = 1; this.pageCount = 0; this.pageSize = 0; this.parameters = Maps.newHashMap(); this.recordCount = 0; this.startRecord = 0; } public List<String> getAdvanceQueryConditions() { return advanceQueryConditions; } public void setAdvanceQueryConditions(List<String> advanceQueryConditions) { this.advanceQueryConditions = advanceQueryConditions; } public List<String> getAdvanceQuerySorts() { return advanceQuerySorts; } public void setAdvanceQuerySorts(List<String> advanceQuerySorts) { this.advanceQuerySorts = advanceQuerySorts; } public boolean getExportAllData() { return exportAllData; } public void setExportAllData(boolean exportAllData) { this.exportAllData = exportAllData; } public List<String> getExportColumns() { return exportColumns; } public void setExportColumns(List<String> exportColumns) { this.exportColumns = exportColumns; } public boolean getExportDataIsProcessed() { return exportDataIsProcessed; } public void setExportDataIsProcessed(boolean exportDataIsProcessed) { this.exportDataIsProcessed = exportDataIsProcessed; } public String getExportFileName() { return exportFileName; } public void setExportFileName(String exportFileName) { this.exportFileName = exportFileName; } public String getExportType() { return exportType; } public void setExportType(String exportType) { this.exportType = exportType; } public List<Map<String, Object>> getExhibitDatas() { return exhibitDatas; } public void setExhibitDatas(List<Map<String, Object>> exhibitDatas) { this.exhibitDatas = exhibitDatas; } public List<Map<String, Object>> getExportDatas() { return exportDatas; } public void setExportDatas(List<Map<String, Object>> exportDatas) { this.exportDatas = exportDatas; } public Map<String, Object> getFastQueryParameters() { return fastQueryParameters; } public void setFastQueryParameters(Map<String, Object> fastQueryParameters) { this.fastQueryParameters = fastQueryParameters; } /** * @WARN 注意使用idea 根据属性生成getter setter时, * boolean值类型的方法名称,ide生成getExport,实际变量名isExport,应生成getIsExport * @return */ public boolean getIsExport() { return isExport; } public void setIsExport(boolean isExport) { this.isExport = isExport; } /** * @WARN 注意使用idea 根据属性生成getter setter时, * boolean值类型的方法名称,ide生成getSuccess,实际变量名IsSuccess,应生成getIsSuccess * @return */ public boolean getIsSuccess() { return isSuccess; } public void setIsSuccess(boolean isSuccess) { this.isSuccess = isSuccess; } public int getNowPage() { return nowPage; } public void setNowPage(int nowPage) { this.nowPage = nowPage; } public int getPageCount() { return pageCount; } public void setPageCount(int pageCount) { this.pageCount = pageCount; } public int getPageSize() { return pageSize; } public void setPageSize(int pageSize) { this.pageSize = pageSize; } public Map<String, Object> getParameters() { return parameters; } public void setParameters(Map<String, Object> parameters) { this.parameters = parameters; } public int getRecordCount() { return recordCount; } public void setRecordCount(int recordCount) { this.recordCount = recordCount; } public int getStartRecord() { return startRecord; } public void setStartRecord(int startRecord) { this.startRecord = startRecord; }
标签:
原文地址:http://my.oschina.net/u/261246/blog/531877