问题描述
我有一个HTML表单,我需要使用HTTP POST和输入数据发布到服务器。
I have an HTML form that I need to post to the server with HTTP POST and input data.
具体来说,我只需要发送所有参数值在表单中选中的复选框。
Specifically, I need to send only the parameter values of all the checkboxes that are checked in the form.
如果用户在10分钟内没有自己完成,我需要这样做。
I need to do it if the user doesn't do it himself in 10 minutes.
我不确定实现这一目标的最佳方法但是现在我正在尝试使用jQuery这样做但遗憾的是我对JavaScipt或jQuery一无所知所以我试图学习它但是没有实现一些简单的事情。
I am not sure the best way to achieve this but for now I am trying to use jQuery do that but sadly I don't know anything about JavaScipt or jQuery so I am trying to learn it but failing to achieve something as simple as that.
我需要在加载表单的页面10分钟后运行以下内容。
I need to the run the following after 10 minutes since the page on which the form is loads.
$("document").ready(function() {
var checkedInputElements = $(":input[value=true]");
var paramNames = [];
jQuery.each(checkedInputElements, function() {
var paramName = $(this).attr("name");
paramNames.push(paramName);
});
$("form").submit(function() {
jQuery.post({
type: 'POST',
url: "http://localhost:8080/wickedlynotsmart/auto-submit-form",
data: paramNames
});
return true;
});
});
我不确定上面的代码是否正确。我还在努力。
有人可以建议我一个指南,我可以用来编写一个计时器,以便在页面加载后10分钟结束后运行此代码吗?
I am not sure if the code above is correct or not. I am still working on it.Could someone suggest me a guide which I could use to write a timer so that this code runs after the 10 minutes are over since the page loads?
谢谢。
编辑:
<%@ include file="/WEB-INF/views/include.jspf" %>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
<!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=ISO-8859-1">
<title>wikedlynotsmart.com</title>
<link rel="stylesheet" type="text/css" href="<c:url value="/resources/syntaxhighlighter/styles/shCore.css" />" />
<link rel="stylesheet" type="text/css" href="<c:url value="/resources/syntaxhighlighter/styles/shThemeDefault.css" />" />
<script type="text/javascript" src="<c:url value="/resources/syntaxhighlighter/scripts/shCore.js" />"></script>
<script type="text/javascript" src="<c:url value="/resources/syntaxhighlighter/scripts/shBrushJava.js" />"></script>
<script type="text/javascript">
SyntaxHighlighter.all()
</script>
<script type="text/javascript" >
//auto-submit-form javascipt code
</script>
</head>
<body>
<jsp:include page="/WEB-INF/views/header.jsp" />
<div id="thing">
<form id="form" action="<c:url value="/wikedlynotsmart/auto-submit-form" />" method="post">
<ol>
<c:forEach items="${things}" var="thing">
<li>${thing.something}</li>
<c:forEach items="${matters}" var="matter">
<table>
<tr>
<td><input type="checkbox" name="tid${thing.id}-mid${matter.id}" value="true"/></td>
<td>${matter.somematter}</td>
</tr>
</table>
</c:forEach><br></br>
</c:forEach>
</ol>
<input type="submit" value="submit the thing" class="button"/>
</form>
</div>
<jsp:include page="/WEB-INF/views/footer.jsp" />
</body>
</html>
这是我正在处理的页面,并试图让事情适合我。
This is the page I am working on and trying to get things work for me.
推荐答案
这样做:
setInterval(submit_me, 600000); // (1000 * 60 * 10 = 600000)
function submit_me() {
$('#form').submit();
}
更短的版本:
setTimeout(function() { $('#form').submit(); }, 5000);
这篇关于如何使用jQuery设置计时器来发送HTML表单的HTTP发布数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!