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