このAjaxコールはうまく動作します。コントローラはコールを受信し、それが何をするかを行います。thymeleafでajaxリクエストパラメータにアクセスする方法
コントローラのメソッド(ここで私は意図的に私は表示する必要があるエラーメッセージをテストするために例外をスローしています)
@RequestMapping(value = "/deleteContentFromMarineCustomer", method = RequestMethod.DELETE, produces = "application/json")
public HttpEntity<String> deleteContentFromMarineCustomer(@RequestParam(value = "srcId") String srcId, @RequestParam(value = "customerId") String customerId, @RequestParam(value = "locale") String locale, @RequestParam(value = "method") String method) {
ResponseEntity<String> responseEntity = null;
try {
// oneChartService.deleteContentFromMarineCustomer(customerId, srcId);
// responseEntity = new ResponseEntity<String>(HttpStatus.OK);
throw new Exception("test");
} catch (Exception e) {
responseEntity = new ResponseEntity<String>("Delete", HttpStatus.SERVICE_UNAVAILABLE);
}
return responseEntity;
}
今私のjsがこの
function deleteSelectedContent() {
var link = "content/deleteContentFromMarineCustomer?srcId=" + srcId + "&customerId=" + customerId + "&locale=" + locale+"&method=Delete";
jQuery.ajax({
url : link,
type : 'DELETE',
success : function(data, status) {
window.location.reload();
},
error : function(data, status) {
jQuery("#errorContentModal").show();
}
});
のように見える表示するときに今私の問題がありますそのページにメソッド名を渡して、適切なメッセージを表示できるようにします。
my html
<div id="errorContentModal" class="modal">
<div class="modal-dialog-content" align="center">
<h3 th:text="#{serviceContentError(${#httpServletRequest.getParameter('method')})}"></h3>
<!--<h3 th:text="#{serviceContentError('Delete')}"></h3>-->
<button class="close" th:text="#{button.ok}"></button>
</div>
</div>
基本的にコメントアウトされた行には、このコードを他の方法で使用できるようにするために、要求から読み取るハードコードされたテキストが含まれています。
問題は#httpServletRequest.getParameter( 'method')がnullを返す問題です。ページへの私の元々の呼び出しはlocale = en_USだったので、この#httpServletRequest.getParameter( 'locale')を実行するとうまくいきます。これは何らかの理由でAjax呼び出しであるため、理解できません。
誰もがこのコードでAjaxリクエストの呼び出しを読み取ることができない理由を知っていますか?