html中post请求如何追加参数呢?
下文笔者讲述html中post请求增加参数的方法及示例分享,如下所示
post提交时增加参数的实现思路: 只需将参数放入到form表单中 然后提交表单即可将参数提交至后台例:html页面
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
<meta charset="UTF-8">
<title>form表单追加请求</title>
<script th:src="@{/js/jquery-3.1.1.js}"></script>
</head>
<body>
<form id="form1" method="post">
<input type="text" name="name" />
<input type="submit" value="请求后台"/>
</form>
<script>
$("#form1").submit(function (e) {
$("#form1").attr("action", "/test/b/b?id=888");
return true;
});
</script>
</body>
</html>
//控制器
@Controller
@RequestMapping("/test")
public class TestController {
@RequestMapping("/b/a")
String a() {
return "backend/a";
}
@ResponseBody
@RequestMapping("/b/b")
String b(String id, String name, HttpServletRequest request) {
String method = request.getMethod();
return method + " : " + id + " : " + name;
}
}
版权声明
本文仅代表作者观点,不代表本站立场。
本文系作者授权发表,未经许可,不得转载。


