ajax(ajaxSubmit)提交form表單

來源:互聯網
上載者:User

標籤:

ajaxSubmit提交form表單

 

依賴指令碼:

1 <script src="<%=request.getContextPath()%>/huangdao/jquery/jquery-form.js" type="text/javascript"></script>

 

HTML

1 <form  id="saveForm" name="form01" class="demoform">2 <input id = "" name="" class="" value=""/>3 <input type="button" class="btn baocun" value="儲存" onclick="savePerosnalInfo();">4 </form>

 

JS

 1 <script type="text/javascript"> 2 function savePerosnalInfo(){ 3  4         var options = { 5                  6                 url : "<%=request.getContextPath()%>/savePersonalInfo.action?id=${info.cardid}", 7                 type : "post", 8                 dataType : "json", 9                 success : function(data){//回呼函數10                     //alert(data);11                     if(data.path=="success"){//返回資訊等於success則提示儲存成功12                         alert(" save success!");13                         //儲存成功之後關閉當前頁面14                         //window.close();15                         //$("#abb").hide();16                         //$(".layer-box").hide();17                         //隱藏頁面(這個頁面是由父頁面控制的,需要找到父頁面的class)18                         $(".layer-box" , parent.document).hide();19                         //在實現關閉儲存頁面的同時發現右側的捲軸消失了,然後添加了下面一句:刪除隱藏標籤20                         $("body", parent.document).removeClass("overhide");21                     }else{22                         alert(" save failed!");23                     }24                 }25         };26         $("#saveForm").ajaxSubmit(options); 27         28 }29 </script>

 

JAVA

 1 @RequestMapping(value = "/savePersonalInfo") 2     public void updatePersonalInfo(HdPersonalInfo info, HttpServletRequest request, 3             HttpServletResponse response, ModelAndView model) { 4              5             String cardid = request.getParameter("id"); 6             info.setCardid(cardid);  7             hdPersonalinfoService.updatePersonalInfoByCardid(info); 8              9             10             String path = "success";11             //JSON對象12             /*方式一*/13             JSONObject jo = new JSONObject();14             jo.put("path",path);15             //1:對響應設定類型 JSON16             response.setContentType("application/json;charset=UTF-8");17             //2:在響應中寫入JSON格式的字串18             try {19                 response.getWriter().write(jo.toString());20             } catch (IOException e) {21                 22                 e.printStackTrace();23             }24 25             26           /*方式二*/27            HashMap<String, String> map = new HashMap<String, String>();28             map.put("path", path);29            net.sf.json.JSONObject testJson = net.sf.json.JSONObject.fromObject(map);30             //1:對響應設定類型 JSON31             response.setContentType("application/json;charset=UTF-8");32             //2:在響應中寫入JSON格式的字串33             34             try {35                 response.getWriter().write(testJson .toString());36             } catch (IOException e) {37                 38                 e.printStackTrace();39             }40         41             42         }

 

ajax(ajaxSubmit)提交form表單

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.