Ajax请求SSM后台时提示:Invalid character found in the request target. The valid characters are defined in RF
生活随笔
收集整理的這篇文章主要介紹了
Ajax请求SSM后台时提示:Invalid character found in the request target. The valid characters are defined in RF
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
場景
前端使用SSM請求后臺時提示:
Invalid character found in the request target. The valid characters are defined in RFC 7230 and RFC 3986
前端請求如下
后臺SSM代碼如下:
@ResponseBody@RequestMapping(value = "/GJbookPayValidate", method = RequestMethod.POST)public Map<String,Object> GJbookPayValidate(PiaoHouGJBookInfoPayViewModel model){try {//登錄賬戶驗證部分BaseSubjectModel bsm = SubjectUtil.validate(this.getClass(),loginType,"機票預訂失敗:");if(!bsm.isFlag()) {return bsm.getJsonResult();}//業務部分return this.service.getGJBookPayValidateJson(model,bsm);}catch (Exception e) {LogService.getInstance(this).debug("機票預訂失敗:"+Status.UNKNOWN_SESSION_EXCEPTION.toString()+e.getMessage());return JsonResult.jsonWsReturn(Status.ERROR.getCode(), Status.ERROR.getDescriptionZh(), Status.ERROR.getCode());}}在 業務中封裝參數的方法:
private static Map<String, Object> setJsonObj(int statusCode, String msg) {Map<String, Object> jsonObj = new HashMap<String, Object>();switch (statusCode) {case 200:jsonObj.put("statusCode", "200");jsonObj.put("message", msg == null ? "操作成功" : msg);break;case 300:jsonObj.put("statusCode", "300");jsonObj.put("message", msg == null ? "操作失敗" : msg);break;}return jsonObj;}實現
可以確定的是在接口請求與返回數據時出現問題。
仔細觀察上面的代碼就會發現問題:
第一次請求驗證接口時返回的結果是一個對象,再次請求時使用
??window.location.href = "${ctx}/frontPage/passFlight/GJbookPay.html?orderId="+data.result;而data.result是一個對象,顯然這樣是不行的,修改為:
$("#book").submit(function() {if($(this).Andrew_Validate("submit_Validate")){$("#book > button:submit").attr("disabled","disabled").text("訂單提交中...");$('#clause').attr("disabled","disabled");var actionurl = $(this).attr("action"); //提交路徑var data = $(this).serialize();console.log(data);$.ajax({async : true,cache : false,type : 'POST',url : actionurl,data : data,success : function(data) {debuggerif("200"==data.statusCode){debugger$.ajax({async : true,cache : false,type : 'POST',url : "${ctx}/frontPage/passFlight/GJbookPay.html",data : data.result});//window.location.href = "${ctx}/frontPage/passFlight/GJbookPay.html?orderId="+data.result;}if("300"==data.statusCode){$("#book > button:submit").removeAttr("disabled","disabled").text("下一步,去支付");$('#clause').removeAttr("disabled","disabled");if(-1==data.result){//請求失敗處理函數webToast(data.message, "middle", "mask", 1000);}else{var contactName=$("#contactName").val();var contactAreaCode=$("#contactAreaCode").val();var contactAreaMobile=$("#contactAreaMobile").val();var email=$("#email").val();var phone=$("#phone").val();var contactCookie = $.cookie("bus__contact");//將聯系人信息存儲到cookie中if(contactCookie && contactCookie!=""){//查看是否是當前登錄用戶的填寫信息contactCookies=contactCookie.split(";"); //字符分割var tempCookie;for(j = 0; j < contactCookies.length; j++) {?tempCookie=contactCookies[j].split(",");if(tempCookie[4]==phone){var s=contactName+','+contactAreaCode+','+contactAreaMobile+','+email+','+phone;contactCookies.splice(j,1,s);$.cookie('bus__contact',contactCookies);}else{var contactResult=contactCookie+";"+contactName+','+contactAreaCode+','+contactAreaMobile+','+email+','+phone;$.cookie('bus__contact',contactResult);}}}else{var contactResult=contactName+','+contactAreaCode+','+contactAreaMobile+','+email+','+phone;$.cookie('bus__contact',contactResult);}Andrew_Popupwin({dom: "#login_dialog_plug_popupWin", //彈窗內容的布局position: "middle", //位置類型(top,bottom,left,right,middle)effectIn: "bounceInDown", //彈窗顯示效果effectOut: "bounceOutDown", //彈窗消失效果maskPosition:"11", //Mask的z-index數值closeBtn: ".login_dialog_plugin_close" //關閉彈窗按鈕})}}},error : function(err) {$("#book > button:submit").removeAttr("disabled","disabled").text("下一步,去支付");$('#clause').removeAttr("disabled","disabled");//請求失敗處理函數webToast("請求錯誤", "middle", "mask", 1000);}});}return false;});
?
總結
以上是生活随笔為你收集整理的Ajax请求SSM后台时提示:Invalid character found in the request target. The valid characters are defined in RF的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Linux-Ubuntu中使用apt进行
- 下一篇: Ajax请求SSM后台传值方式踩坑