當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Jquery中使用ajax传json参数并从SpringBoot后台Controller返回消息
生活随笔
收集整理的這篇文章主要介紹了
Jquery中使用ajax传json参数并从SpringBoot后台Controller返回消息
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
場景
前端通過ajax提交json格式的數據,后臺接受到實現具體的業務后
返回給前端消息提示。
實現
html頁面代碼
?<button id="printBtn" class="btn btn-info " type="button"><i class="fa fa-trash-o"></i> 打印</button>調用js部分代碼
//打印按鈕點擊事件$("#printBtn").click(function () {var data = t.rows(['.selected']).data()[0];if(undefined===data){swal({type: 'warning',title: '提示:',text: '請首選選擇一行數據!',confirmButtonColor: "#1ab394",})}else{printCode(data.id);}});ajax請求方法
function printCode(id){debugger$.ajax({type: 'POST',url: "/wmsReceiveOrder/doPrintPostRequest",cache: false,? //禁用緩存data:JSON.stringify({"id":id}),contentType: "application/json",dataType: "json",success: function (result) {debuggeralert(result.message)}})return false; }來到url所對應的后臺Controller中的方法
@ResponseBody@RequestMapping(value = "/doPrintPostRequest")public Map<String, Object> doPrintPostRequest(@RequestBody Map<String, Object> params) {Map<String, Object> result = new HashMap<String, Object>();Object PrintId = params.get("id");String paramID="";if(PrintId!=null){paramID=PrintId.toString();}result.put("statusCode",? "200");result.put("message", "參數是:"+ paramID);return result;}效果
總結
以上是生活随笔為你收集整理的Jquery中使用ajax传json参数并从SpringBoot后台Controller返回消息的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Jquery中发送ajax请求示例代码
- 下一篇: SpringBoot中使用thymele