方法 $.post(url,params,function(data){});
創(chuàng)新互聯(lián)堅持“要么做到,要么別承諾”的工作理念,服務(wù)領(lǐng)域包括:成都網(wǎng)站設(shè)計、成都網(wǎng)站建設(shè)、企業(yè)官網(wǎng)、英文網(wǎng)站、手機端網(wǎng)站、網(wǎng)站推廣等服務(wù),滿足客戶于互聯(lián)網(wǎng)時代的漢陽網(wǎng)站設(shè)計、移動媒體設(shè)計的需求,幫助企業(yè)找到有效的互聯(lián)網(wǎng)解決方案。努力成為您成熟可靠的網(wǎng)絡(luò)建設(shè)合作伙伴!
表單的action,method屬性都沒有
input 的類型只能為button不能為submit只能為button,否則點擊button會執(zhí)行表單action,不會走jquery異步
前臺代碼
<script type="text/javascript"> $(function() { //異步提交表單 $("#save").click(function(){ $.post("${ctx}/order/save.action",$("#form1").serialize(),function(data){ if(data=="true") { alert ("備注保存成功"); } }) }) }) </script> <form id="form1" > <input type="hidden" name ="oid" value="${orderVo.id}"> <textarea class="form-control" name ="remark" id ="text" rows="3" cols="140" >${orderVo.remark}</textarea> <input id="save" class="btn btn-primary" type="button" value="保存" />
后臺代碼:
public void save(){ PrintWriter out=null; try { System.out.println(oid); System.out.println(remark); orderService.saveRemark(oid,remark); HttpServletResponse response=ServletActionContext.getResponse(); out=response.getWriter(); out.print(true); out.flush(); out.close(); } catch (Exception e) { e.printStackTrace(); out.flush(); out.close(); out.println(0); } }
webx框架
velocity模板實現(xiàn)代碼
分頁bean
package com.alibaba.uyuni.biz.common.bo.dto; import java.io.Serializable; import com.alibaba.uyuni.common.enums.NumEnum; /** * 類Page.java的實現(xiàn)描述:TODO 類實現(xiàn)描述 * * @author 楊冬 2014年8月21日 下午1:19:25 */ public class UyuniPage<T> implements Serializable { /** * */ private static final long serialVersionUID = 8104777827863916550L; /** 每頁顯示記錄數(shù) **/ private Integer pageSize; /** 查詢的集合 **/ private T data; /** 總頁數(shù) **/ private int totalPage; /** 當前頁,第幾頁 **/ private Integer pageIndex; /** 總記錄數(shù) **/ private Integer totalNum; /** 是否有下頁 **/ private boolean hasNextPage = false; /** 是否有上頁 **/ private boolean hasPreviousPage = false; /** * @param pageSize 每頁條數(shù) * @param pageIndex 當前頁,第幾頁 * @param totalNum 總記錄數(shù) * @param data 查詢的集合 */ public UyuniPage(Integer pageSize, Integer pageIndex, Integer totalNum, T data){ super(); if (pageSize == null || pageSize == 0) { pageSize = NumEnum.FIVE.getValue(); } if (pageIndex == null || pageIndex == 0) { pageIndex = NumEnum.ONE.getValue(); } if (totalNum == null || totalNum == 0) { totalNum = 0; } this.pageSize = pageSize; this.data = data; // pageSize==0會報錯 this.totalPage = (totalNum % pageSize == 0) ? (totalNum / pageSize) : (totalNum / pageSize + 1); this.pageIndex = (pageIndex == 0) ? (1) : (pageIndex); this.totalNum = totalNum; this.hasNextPage = (this.totalPage > 1 && this.totalPage > this.pageIndex); this.hasPreviousPage = (this.pageIndex > 1); } /** * @return the pageSize */ public Integer getPageSize() { return pageSize; } /** * @param pageSize the pageSize to set */ public void setPageSize(Integer pageSize) { this.pageSize = pageSize; } /** * @return the data */ public T getData() { return data; } /** * @param data the data to set */ public void setData(T data) { this.data = data; } /** * @return the totalPage */ public int getTotalPage() { return totalPage; } /** * @param totalPage the totalPage to set */ public void setTotalPage(int totalPage) { this.totalPage = totalPage; } /** * @return the pageIndex */ public Integer getPageIndex() { return pageIndex; } /** * @param pageIndex the pageIndex to set */ public void setPageIndex(Integer pageIndex) { this.pageIndex = pageIndex; } /** * @return the totalNum */ public Integer getTotalNum() { return totalNum; } /** * @param totalNum the totalNum to set */ public void setTotalNum(Integer totalNum) { this.totalNum = totalNum; } /** * @return the hasNextPage */ public boolean isHasNextPage() { return hasNextPage; } /** * @param hasNextPage the hasNextPage to set */ public void setHasNextPage(boolean hasNextPage) { this.hasNextPage = hasNextPage; } /** * @return the hasPreviousPage */ public boolean isHasPreviousPage() { return hasPreviousPage; } /** * @param hasPreviousPage the hasPreviousPage to set */ public void setHasPreviousPage(boolean hasPreviousPage) { this.hasPreviousPage = hasPreviousPage; } /** * @return the serialversionuid */ public static long getSerialversionuid() { return serialVersionUID; } }
vm頁面
<script src="http://libs.baidu.com/jquery/2.0.0/jquery.js"></script> <script type="text/javascript"> $(function() { $("#confirm").click(function(){ var studentId=$("#studentId").val(); if(studentId==""){ alert("新增學(xué)生"); $.ajax({ url:"/project/studentRpc/newStudent.json", type:"post", data:$('#studentform').serialize(), dataType: 'json', success:function(data){ var isAdd= data.content.successed; if(isAdd==true){ alert("新增成功"); window.location.reload(); } } }); }else{ //更新學(xué)生 $.ajax({ url:"/project/studentRpc/"+studentId+"/updateStudent.json", type:"post", data:$('#studentform').serialize(), dataType: 'json', success:function(data){ var isDeleted= data.content.successed; if(isDeleted==true){ alert("更新成功"); window.location.reload(); } } }); } }) }) </script> </head> <body> #if(${studentDto.id}) 修改 #else 新增 #end <form id="studentform"> <input id="studentId" type="hidden" name="id" value="$!studentDto.id"><br> 姓名<input type="text" name="name" value="$!studentDto.name"><br> 年齡<input type="text" name="age" value="$!studentDto.age"><br> 性別<input type="text" name="sex" value="$!studentDto.sex"><br> 年級<input type="text" name="grade" value="$!studentDto.grade"><br> 班級<input type="text" name="team" value="$!studentDto.team"><br> 老師<input type="text" name="teacher" value="$!studentDto.teacher"><br> </form> <button id="confirm">提交</button> </body>
buttom標簽必須放到form標簽外面,否則點擊button會執(zhí)行表單action,不會走綁定的異步事件
分頁顯示頁面
#set($nextpage=$pb.pageIndex + 1) #set($previouspage=$pb.pageIndex - 1) #if($pb.hasPreviousPage == true) <a href="/project/student/studentshow.htm?pageIndex=$previouspage">上一頁</a> #end #if($pb.hasNextPage == true) <a href="/project/student/studentshow.htm?pageIndex=$nextpage">下一頁</a> #end <br> #foreach(${studentDto} in ${result}) <tr> <td>${studentDto.id}</td> <td>${studentDto.name}</td> <td>${studentDto.age}</td> <td>${studentDto.sex}</td> <td>${studentDto.grade}</td> <td>${studentDto.team}</td> <td>${studentDto.teacher} </td> <td><a href="/project/student/form.htm?studentId=${studentDto.id}">編輯</a></td> <td><a href="javascript:void(0);" onclick = "return delStudent(${studentDto.id});">刪除</a></td> </tr> <br> #end <a href="/project/student/form.htm">新增</a> </div>
vm做加減運算必須在set標簽里面做,且運算符兩邊必須有空格
#set($a=10) #set($b=$a - 1) ------------ <span>$b</span>
不能直接像freemaker一樣 ${b-1}
http://liu400liu.iteye.com/blog/1197466
參考文章:
http://1194867672-qq-com.iteye.com/blog/1945827
網(wǎng)站名稱:Jquery異步提交表單(post)
轉(zhuǎn)載來于:http://jinyejixie.com/article46/ggspeg.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供軟件開發(fā)、網(wǎng)站建設(shè)、定制網(wǎng)站、營銷型網(wǎng)站建設(shè)、建站公司、關(guān)鍵詞優(yōu)化
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)