form表單數(shù)據(jù)封裝成json格式并提交給服務(wù)器的實(shí)現(xiàn)方法
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" style="width:34px;position:absolute;right:0px;top:0px;"></img> <h2 style="font-weight: bolder;font-size: 14px;">更改該注冊(cè)訂單的收費(fèi)狀態(tài)</h2> <ul> <li> <label for="report"> 是否已報(bào)到: </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"> 注冊(cè)類型: </label> <span id="costType"></span> </li> <li> <label for="sure_fee"> 在線支付手續(xù)費(fèi): </label> <span id="costType">0</span> </li> <li> <label for="sure_fee"> 應(yīng)收費(fèi)金額: </label> <span id="price"></span> </li> <li> <label for="already_fee"> 已收費(fèi)金額: </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"/>現(xiàn)金 <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"> 發(fā)票抬頭: </label> <span id="billTitle"></span> </li> <li> <label for="fa_piao"> 發(fā)票編號(hào): </label> <input type="text" id="billCode" name="billCode"/> </li> <li> <label for="check_evidence"> 是否已開發(fā)票: </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"> 是否已領(lǐng)發(fā)票: </label> <input type="radio" id="isDrawBill1" name="isDrawBill" value="1"/>是 <input type="radio" id="isDrawBill0" name="isDrawBill" value="0"/>否 </li> <li> <label for="date"> 已發(fā)確認(rèn)日期: </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">是否已發(fā)確認(rèn)函:</label> <span id="isConfirmInvitation"></span> </li> <li> <label for="fa_piao">在線支付狀態(tài):</label> <span id="payString"></span> </li> </ul> <div class="fee_opr"> <button type="button" class="fee_sure" style="border: none;background: #003260;color: #ffffff;padding: 3px 30px;margin-left: 10px;border-radius: 0px;">確定</button> <button type="button" class="fee_cancel" style="border: none;background: #003260;color: #ffffff;padding: 3px 30px;margin-left: 10px;border-radius: 0px;">關(guān)閉</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("請(qǐng)選擇付款類型"); 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、后臺(tái)action處理:
@RequestMapping(params ="method=saveUserMessage",method=RequestMethod.POST) //導(dǎo)入發(fā)言 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表單數(shù)據(jù)封裝成json格式并提交給服務(wù)器的實(shí)現(xiàn)方法就是小編分享給大家的全部?jī)?nèi)容了,希望能給大家一個(gè)參考,也希望大家多多支持腳本之家。
相關(guān)文章
js實(shí)現(xiàn)數(shù)據(jù)雙向綁定(訪問器監(jiān)聽)
這篇文章主要為大家詳細(xì)介紹了采用訪問器監(jiān)聽的方式實(shí)現(xiàn)簡(jiǎn)單數(shù)據(jù)雙向綁定,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2021-09-09JavaScript實(shí)現(xiàn)的字符串replaceAll函數(shù)代碼分享
這篇文章主要介紹了JavaScript實(shí)現(xiàn)的字符串replaceAll函數(shù)代碼分享,本文直接給出實(shí)現(xiàn)代碼,需要的朋友可以參考下2015-04-04PHP讀取遠(yuǎn)程txt文檔到數(shù)組并實(shí)現(xiàn)遍歷
這篇文章主要介紹了PHP讀取遠(yuǎn)程txt文檔到數(shù)組并實(shí)現(xiàn)遍歷,文中通過示例代碼介紹的非常詳細(xì),對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友可以參考下2020-08-08js實(shí)現(xiàn)適配移動(dòng)端的拖動(dòng)效果
這篇文章主要為大家詳細(xì)介紹了js實(shí)現(xiàn)適配移動(dòng)端的拖動(dòng)效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-01-01javascript對(duì)JSON數(shù)據(jù)排序的3個(gè)例子
這篇文章主要介紹了javascript對(duì)JSON數(shù)據(jù)排序的3個(gè)例子的相關(guān)資料2014-04-04