SJS*_*SJS 2 javascript jquery query-string
我想发送一个 ajax 请求,但我试图构建的查询字符串是空的。
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>This is a project to show how to use RESTful</title>
</head>
<body>
<script type="text/javascript">var contexPath = "<%=request.getContextPath()%>";</script>
<script src="<%=request.getContextPath()%>/js/jquery.js"></script>
<script type="text/javascript">
function doAjaxPost() {
var queryString = $('#htmlform') // empty
alert("doAjaxPost Called:" + queryString + ":");
$.ajax({
...
...
});
}? </script>
<H1>Add Employee</H1>
<p>
<form name="htmlform">
<table border=1>
<thead><tr>
<th>ID</th>
<th>Name</th>
<th>Email</th>
</tr></thead>
<tr>
<td><input type="text" name="ID" maxlength="5" size="3"></td>
<td><input type="text" name="Name" maxlength="10" size="10"></td>
<td><input type="text" name="Email" maxlength="10" size="10"></td>
</tr>
</table>
<input type="button" value="Save Employee" onclick="doAjaxPost();" />
<p>
<p>
</form>
[<a href="http://localhost:8080/RESTful/service/employees">List all Employees</a> | <a href="add.jsp">Employee Form Test</a>]
</body>
</html>
Run Code Online (Sandbox Code Playgroud)
更改自:
<form name="htmlform">
Run Code Online (Sandbox Code Playgroud)
到:
<form id="htmlform">
Run Code Online (Sandbox Code Playgroud)
来自:
var queryString = $('#htmlform')
Run Code Online (Sandbox Code Playgroud)
到:
var queryString = $('#htmlform').serialize();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3572 次 |
| 最近记录: |