您好,登錄后才能下訂單哦!
小編給大家分享一下form表單數據如何封裝成json格式并提交給服務器,相信大部分人都還不怎么了解,因此分享這篇文章給大家參考一下,希望大家閱讀完這篇文章后大有收獲,下面讓我們一起去了解一下吧!
1、jsp代碼,form表單:
<form action="#" id="costForm"> <input type="hidden" id="userId" name="userId"/> <div id="COST"> <img src='<%=path %>/cvc/center/images/close.png' class="close" ></img> <h3 >更改該注冊訂單的收費狀態</h3> <ul> <li> <label for="report"> 是否已報到: </label> <input type="radio" id="baodao1" name="baodao" value="1"/>是 <input type="radio" id="baodao0" name="baodao" value="0"/>否 </li> <li> <label for="name"> 姓 名: </label> <span id="costName"></span> </li> <li> <label for="type"> 注冊類型: </label> <span id="costType"></span> </li> <li> <label for="sure_fee"> 在線支付手續費: </label> <span id="costType">0</span> </li> <li> <label for="sure_fee"> 應收費金額: </label> <span id="price"></span> </li> <li> <label for="already_fee"> 已收費金額: </label> <input type="text" id="pay_" name="pay"/> </li> <li> <label for="owe"> 欠 款: </label> <span id="qianPay"></span> </li> <li> <label for="fee_type"> 付款方式: </label> <input type="radio" id="payType1" name="payType" value="3"/>銀行 <input type="radio" id="payType2" name="payType" value="4"/>郵局 <input type="radio" id="payType3" name="payType" value="5"/>現金 <input type="radio" id="payType4" name="payType" value="2"/>在線支付 </li> <li> <label for="fee_evidence"> 是否收到匯款憑證: </label> <input type="radio" id="isReceiveProof1" name="isReceiveProof" value="1"/>是 <input type="radio" id="isReceiveProof0" name="isReceiveProof" value="0"/>否 </li> <li> <label for="fa_piao"> 發票抬頭: </label> <span id="billTitle"></span> </li> <li> <label for="fa_piao"> 發票編號: </label> <input type="text" id="billCode" name="billCode"/> </li> <li> <label for="check_evidence"> 是否已開發票: </label> <input type="radio" id="isBill1" name="isBill" value="1"/>是 <input type="radio" id="isBill0" name="isBill" value="0"/>否 </li> <li> <label for="get_evidence"> 是否已領發票: </label> <input type="radio" id="isDrawBill1" name="isDrawBill" value="1"/>是 <input type="radio" id="isDrawBill0" name="isDrawBill" value="0"/>否 </li> <li> <label for="date"> 已發確認日期: </label> <span id="confirmDate"></span> <!-- <input type="text" id="confirmDate" name="confirmDate"/> --> <!-- <input id="confirmDate" name="confirmDate" class="text" type="text" onClick="WdatePicker()"/> --> </li> <li> <label for="check_letter">是否已發確認函:</label> <span id="isConfirmInvitation"></span> </li> <li> <label for="fa_piao">在線支付狀態:</label> <span id="payString"></span> </li> </ul> <div class="fee_opr"> <button type="button" class="fee_sure" >確定</button> <button type="button" class="fee_cancel" >關閉</button> </div> </div> </form>
2、js代碼:
$(".fee_sure").click(function () { var dataObj = $("#costForm").serialize(); var payType = $('input[name="payType"]:checked').val(); if(payType == undefined){ alert("請選擇付款類型"); return ; }else{ $.ajax({ url:"/webCenter.do?method=saveUserMessage", type: "post", dataType:"json", data:dataObj, cache:false, ifModified:true, success:function(json){ if(json.flag == 1){ alert("1234"); } } }) } })
3、后臺action處理:
@RequestMapping(params ="method=saveUserMessage",method=RequestMethod.POST) //導入發言 public void saveUserMessage(int userId,HttpServletRequest request,HttpServletResponse response){ try { HttpSession session = this.getSession(request); Adminuser adminUser = session.getAttribute("centerAdminUser") == null?null:(Adminuser) session.getAttribute("centerAdminUser"); if(adminUser == null){ try { response.sendRedirect(request.getContextPath()+"/center/index.jsp"); } catch (Exception e) { e.printStackTrace(); } }else{ String billNumber = request.getParameter("billCode")==null?"":request.getParameter("billCode"); String isBaodao = request.getParameter("baodao")==null?"0":request.getParameter("baodao"); String haspay = request.getParameter("pay")==null?"0":request.getParameter("pay"); String payType = request.getParameter("payType")==null?"0":request.getParameter("payType"); String isFkpz = request.getParameter("isReceiveProof")==null?"0":request.getParameter("isReceiveProof"); String isYkfp = request.getParameter("isBill")==null?"0":request.getParameter("isBill"); String isYlfp = request.getParameter("isDrawBill")==null?"0":request.getParameter("isDrawBill"); JSONObject jsonObject = new JSONObject(); //AdminuserConferences adminuserConferences = webService.getAdminuserConferences(adminUser.getAdminuserId()); UserInfo userInfo = webService.getUserInfoById(userId); if(userInfo!=null) { jsonObject.accumulate("flag",1); ChcRegUser chcRegUser = webService.getChcRegUser(userId); if(chcRegUser!=null) { chcRegUser.setHasPay(Integer.parseInt(haspay)); chcRegUser.setPayType(Integer.parseInt(payType)); if(chcRegUser.getHasPay()-chcRegUser.getPay()==0) { chcRegUser.setStateType(1); } webService.saveObject(chcRegUser); userInfo.setIsBaodao(Integer.parseInt(isBaodao)); userInfo.setIsFkpz(Integer.parseInt(isFkpz)); userInfo.setBillNumber(billNumber); userInfo.setIsYlfp(Integer.parseInt(isYlfp)); userInfo.setIsYkfp(Integer.parseInt(isYkfp)); webService.saveObject(userInfo); jsonObject.accumulate("pay", chcRegUser.getPay()); jsonObject.accumulate("haspay", chcRegUser.getHasPay()); } }else { jsonObject.accumulate("flag",0); } writeJson(response, jsonObject.toString()); } } catch (Exception e) { e.printStackTrace(); } }
以上是“form表單數據如何封裝成json格式并提交給服務器”這篇文章的所有內容,感謝各位的閱讀!相信大家都有了一定的了解,希望分享的內容對大家有所幫助,如果還想學習更多知識,歡迎關注億速云行業資訊頻道!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。