日期:2014-05-16  浏览次数:20906 次

ajaxSubmti() 实例

1、answer.jsp内容如下:

?

<%@ page language="java" pageEncoding="UTF-8"%>
<%
	out.println("中国人");
%>

?

2、使用另一个页面来请求这个页面,代码如下:

?

<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<base href="<%=basePath%>">	
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<script language="javascript"  src="<%=basePath%>JQuery/jquery-1.6.js"></script>
		<script language="javascript"  src="<%=basePath%>JQuery/jquery.validate.js"></script>
		<script language="javascript"  src="<%=basePath%>JQuery/jquery.form.js"></script>		
		<title>Welcome Here</title>
		<script type="text/javascript">
			function submitForm() {
				$('#ajaxSubmitForm').ajaxSubmit(function(msg){
					alert(msg);
					window.location.href='http://www.google.cn.hk';
				});
			}		
		</script>
	</head>
	<body>
		<form action="answer.jsp" method="post" id="ajaxSubmitForm">
			<input type="button" value="Submit" onclick="submitForm();">
		</form>
	</body>
</html>

?

3、页面中form 的action 中的值是:answer.jsp,点击“submit” 按钮后,弹出“中国人”的提示信息,然后页面跳转到google。

4、总结:使用ajaxSubmit提交页面,当前页面不跳转,待提交的数据处理完成后,返回信息。?