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("網(wǎng)絡連接不通,請稍后再試!");
},
success: function(data) {
callback(data, options);
}
};
if ( !! options) {
option = $.extend(option, options);
}
$.ajax(option);
}
};
當我想要通過回調(diào)函數(shù)success獲取data時,一開始我是直接在后臺return一個json字符串,結果會報異常,沒定義方法什么的,后來查了下,需要通過response.getWriter().write()方法寫入數(shù)據(jù),success中才能獲取到數(shù)據(jù)。后臺代碼如下:
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;
}
以上所述是小編給大家介紹的Ajax中通過response在后臺傳遞數(shù)據(jù),希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!