关于Ajax中通过response在后台传递数据问题
这是js代码:
var System = { getHttpRequest: function(url, callback, options) { if (url.length < 0) return; var option = { url: url, type: "get", dataType: "json", cache: false, timeout: 30000, beforeSend: function(XHR) { }, complete: function(XHR, textStatus) { XHR.abort(); }, error: function(XMLHttpRequest, textStatus, errorThrown) { //alert("网络连接不通,请稍后再试!"); }, success: function(data) { callback(data, options); } }; if ( !! options) { option = $.extend(option, options); } $.ajax(option); } };
当我想要通过回调函数success获取data时,一开始我是直接在后台return一个json字符串,结果会报异常,没定义方法什么的,后来查了下,需要通过response.getWriter().write()方法写入数据,success中才能获取到数据。后台代码如下:
public String getRejectReason() throws Exception{ String rowId = getParameterAndPut("rowId",null,0).toString(); String jsonData = ""; if (StringUtils.isNotEmpty(rowId)) { jsonData = newOwnerInfoService.getRejectReasonJsonData(rowId); } this.getResponse().setCharacterEncoding("utf-8"); this.getResponse().getWriter().write(jsonData); return null; }
总结
相关推荐
kentrl 2020-11-10
结束数据方法的参数,该如何定义?-- 集合为自定义实体类中的结合属性,有几个实体类,改变下标就行了。<input id="add" type="button" value="新增visitor&quo
ajaxyan 2020-11-09
zndy0 2020-11-03
学留痕 2020-09-20
Richardxx 2020-11-09
learningever 2020-09-19
chongxiaocheng 2020-08-16
ajaxhe 2020-08-16
lyqdanang 2020-08-16
curiousL 2020-08-03
TONIYH 2020-07-22
时光如瑾雨微凉 2020-07-19
83510998 2020-07-18
坚持着执着 2020-07-16
jiaguoquan00 2020-07-07
李永毅 2020-07-05
坚持着执着 2020-07-05