$(function(){ // 訂單取消 $("#cancel").click(function() { if (confirm("${message("yee.member.order.cancelConfirm")}")) { $.ajax({ url: "${base}/member/order/cancel.jhtml?sn=${order.sn}", type: "POST", dataType: "json", cache: false, success: function(message) { if (message.type == "success") { location.reload(true); } else { $.message(message); } } }); } return false; }); });
頁面提交方法如上,後臺以下:html
/** * 取消 */ @RequestMapping(value = "/cancel", method = RequestMethod.POST) public @ResponseBody Message cancel(String sn) { Order order = orderService.findBySn(sn); if (order == null) { return ERROR_MESSAGE; } Member member = memberService.getCurrent(); if (!member.equals(order.getMember())) { return ERROR_MESSAGE; } if (order.hasExpired() || (!Order.Status.pendingPayment.equals(order.getStatus()) && !Order.Status.pendingReview.equals(order.getStatus()))) { return ERROR_MESSAGE; } if (orderService.isLocked(order, member, true)) { return Message.warn("yee.member.order.locked"); } orderService.cancel(order); return SUCCESS_MESSAGE; }
前臺提交報出:Request method 'POST' not supported。java
解決方法:前臺去掉type: "POST",後臺去掉 method = RequestMethod.POST。ajax