get方式長度受限,如何將較長資料傳遞到後臺
阿新 • • 發佈:2019-02-03
get方式長度有限制,所以只能用post方式
$.ajax({
url:"${_baseUrl}/dd/sendDataToServer",
type:'post', //資料傳送方式
data:{tableJson:tableJson},
async: false,
success: function(response, status, request){
window.location.href="${_baseUrl}/dd/exportDoc" ;
},
error:function(XMLHttpRequest, textStatus, errorThrown){
/* alert(XMLHttpRequest.status);
alert(XMLHttpRequest.readyState);
alert(textStatus); */
layer.msg("系統錯誤", {offset:['85%','45%']});
}
});
通過post將資料傳遞到後臺,快取在session或者servletContext中
@RequestMapping(value = "sendDataToServer",method = RequestMethod.POST,produces = "text/plain; charset=utf-8")
public void exportDocOfDesignTestTrack1(HttpServletResponse response){
String tableJson = request.getParameter("tableJson");
HttpSession session = request.getSession();
session.setAttribute("tableJson" , tableJson);
}
然後在ajax的回撥方法中,再去訪問後臺,獲取session中的資料,去做邏輯處理;獲取資料後清理快取
@RequestMapping(value = "exportDoc",method = RequestMethod.GET,produces = "text/plain; charset=utf-8")
public void exportDoc(HttpServletResponse response){
documentSetionService.setUnlimitedLicense();
HttpSession session = request.getSession();
String tableJson = (String) session.getAttribute("tableJson");
session.removeAttribute("tableJson");
}