jQuery.form.js提交表单

嵇浩然
2023-12-01

前端页面:

<%@ page language="java" contentType="text/html; charset=utf-8"
	pageEncoding="utf-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
<title>test</title>
<script src="<c:url value='/jquery/jquery-1.12.4.js'/>"></script>
<script src="<c:url value='/jquery/jquery.form.js'/>"></script>
<script type="text/javascript">
 window.onload = function() {
			$("form.change_form").ajaxForm(function() {
				alert("操作成功");
				location.reload(true);//刷新当前页面
			});
	} 
</script>
</head>
<body>
	<form class="change_form" action="<c:url value='/TestServlet2'/>" method="post">
		<input type="hidden" name="method" value="resetPassword" /> <input
			type="hidden" name="uid" value="1234567" />
		<button type="submit" class="sub_btn">提交</button>
	</form>
</body>
</html>

Java后台:

public class TestServlet2 extends HttpServlet {
	public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException  {
		System.out.println("servlet run");		
		String uid = request.getParameter("uid");
		System.out.println(uid);
		}
}

第一次使用jQuery.form,开始用的jQuery1.5.1,提交表单后会调用2次回调函数,后来换成jQuery1.12.4后就好了,应该是版本的问题。

 类似资料: