gpt4 book ai didi

javascript - 使用 jQuery 创建格式不正确的查询字符串不起作用

转载 作者:行者123 更新时间:2023-11-29 16:20:20 25 4
gpt4 key购买 nike

我想发送一个 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>

最佳答案

更改自:

<form name="htmlform">

收件人:

<form id="htmlform">

来自:

var queryString = $('#htmlform')

收件人:

var queryString = $('#htmlform').serialize();

关于javascript - 使用 jQuery 创建格式不正确的查询字符串不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11020769/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com