Ajax异步提交from表单

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!DOCTYPE html>
<html>
<head>
<base href="<%=basePath%>">
<meta charset="UTF-8">
<title>Insert title here</title>
<!-- 引入jQuery 核心库,这里采用的是2.0 -->
<script type="text/javascript" src="easyui/jquery.min.js"></script>
<!-- 引入jQuery EasyUI 核心库,这里采用的是1.3.6 -->
<script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
<!-- 引入EasyUI 中文提示信息 -->
<script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>
<!-- 引入EasyUI 核心UI 文件CSS -->
<link rel="stylesheet" type="text/css"
	href="easyui/themes/default/easyui.css" />
<!-- 引入EasyUI 图标文件 -->
<link rel="stylesheet" type="text/css" href="easyui/themes/icon.css" />
</head>
<body>
<script type="text/javascript">
	$(function(){
		$("#gbut").click(function(){
			var gtitle=$("#gtitle").val();
			var gcontent=$("#gcontent").val();
			var gstartime=$('#gstartime').datetimebox('getValue');
			var gendtitme=$('#gendtitme').datetimebox('getValue');
			$("#ugongao").form('submit',{
				url:'gongao/updategongao.action',
				onSubmit:function(){
					if(gstartime==""){
						$.messager.alert('我的消息','生效时间不能为空!','warning');
						return false;
					}
					if(gtitle==""){
						$.messager.alert('我的消息','标题不能为空!','warning');
						return false;
					}
					if(gcontent==""){
						$.messager.alert('我的消息','内容不能为空!','warning');
						return false;
					}
				},
				success:function(e){
					$("#gongao_div").dialog('close');
					$("#gongao").datagrid('reload');
					if(e!=""){
					$.messager.show({
						title:'我的消息',
						msg:e,
						showType:'show',
						style:{
							top:document.body.scrollTop+document.documentElement.scrollTop,
						}
					});
					}
				}
			});
		});
	});

</script>
<div align="center">
	<h2>修改公告</h2>
	<form id="ugongao" method="post">
	<table border="1">
		<tr>
			<td>标题:</td>
			<td><input type="text" id="gtitle" name="gtitle" value="${gongao.gtitle}"/></td>
		</tr>
		<tr>
			<td>内容:</td>
			<td>
			<textarea rows="10" cols="30" style="resize: none;" id="gcontent" name="gcontent">${gongao.gcontent}</textarea>
			</td>
		</tr>
		<tr>
			<td>生效时间:</td>
			<td><input type="text" id="gstartime" name="gstartime" class="easyui-datetimebox" value="${gongao.gstartime}" />
			</td>
		</tr>
		<tr>
			<td>失效时间:</td>
			<%-- value="<fmt:formatDate value="${inbox.idate }" pattern="yyyy-MM-dd hh:mm:ss"/> --%>
			<td><input type="text" id="gendtitme" name="gendtitme" class="easyui-datetimebox" value="${gongao.gendtitme}"/>
				<input type="hidden" name="gstauts" value="${gongao.gstauts }"/>
				<input type="hidden" name="gid" value="${gongao.gid}"/>
				<input type="hidden" name="gsid" value="${gongao.gsid }"/>
			</td>
		</tr>
		<tr>
		
			<td colspan="2"><p align="center" style="letter-spacing:20px "><input type="button" value="提交" id="gbut">
				<input type="button" value="清空" id="gbut2"></p>
			</td>
		</tr>
	</table>
	</form>
</div>
</body>
</html>

猜你喜欢

转载自blog.csdn.net/weixin_44315761/article/details/90610744
今日推荐