form_test.jsp
2.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<script type="text/javascript" src="<%=request.getContextPath() %>/resource/library/js/jquery-1.11.3.js"></script>
<script>
$(function() {
$("#ajaxBtn").click(function() {
var params = $("#myform").serializeObject(); //将表单序列化为JSON对象
$.post("<%=request.getContextPath()%> /rest/eptMenu/insert", params, function(data) {
alert(data);
}, "json");
console.info(params);
})
})
$.fn.serializeObject = function() {
var o = {};
var a = this.serializeArray();
$.each(a, function() {
if (o[this.name]) {
if (!o[this.name].push) {
o[this.name] = [ o[this.name] ];
}
o[this.name].push(this.value || '');
} else {
o[this.name] = this.value || '';
}
});
return o;
}
</script>
</head>
<body>
<form id="myform">
<table>
<tr>
<td>菜单名称:</td>
<td> <input type="text" name="menuName" /> </td>
</tr>
<tr>
<td>父菜单ID:</td>
<td> <input type="text" name="parentId" /> </td>
</tr>
<tr>
<td>URL:</td>
<td> <input type="text" name="menuUrl" /> </td>
</tr>
<tr>
<td>排序:</td>
<td> <input type="text" name="sortId" /> </td>
</tr>
<tr>
<td>是否底部显示:</td>
<td>
<input type="radio" value="1" name="isTop">是
<input type="radio" value="0" name="isTop">否
</td>
</tr>
<tr>
<td colspan="2">
<input type="button" id="ajaxBtn" value="提交" />
</td>
</tr>
</table>
</form>
</body>
</html>