Javascript设置超时表单数据
我有一个html表单:Javascript设置超时表单数据,javascript,php,jquery,html,forms,Javascript,Php,Jquery,Html,Forms,我有一个html表单: <form method="post" action="login-autentica" id="loginform" class="input-wrapper blue-gradient glossy" title="Login"> <ul class="inputs black-input large"> <li><span class="icon-user mid-margin-right">&
<form method="post" action="login-autentica" id="loginform" class="input-wrapper blue-gradient glossy" title="Login">
<ul class="inputs black-input large">
<li><span class="icon-user mid-margin-right"></span>
<input type="text" name="porta" id="username" value="" class="input-unstyled" placeholder="Porta" autocomplete="off">
</li>
<li><span class="icon-lock mid-margin-right"></span>
<input type="password" name="senha" id="password" value="" class="input-unstyled" placeholder="Senha" autocomplete="off">
</li>
</ul>
<p class="button-height">
<button type="submit" class="button glossy float-right" id="login">Entrar</button>
<input type="checkbox" name="remind" id="remind" value="1" checked="checked" class="switch tiny mid-margin-right with-tooltip" title="Habilitar Auto-Login">
<label for="remind">Lembrar</label>
</p>
</form>
问题出现在以下陈述中:
“setTimeout(函数(){document.location.href='url'},2000);”
我的表单html将数据发送到名为'login-autentica.php'
的php文件,问题是setTimeout
无法将数据发送到php,返回错误
我希望当用户单击“提交”
时,在setTimeout()
中提到的时间段之后,从HTML表单捕获数据并发送到“login autentica.php”
谢谢您的帮助,请原谅我的英语,我来自巴西…您在setTimeout中使用document.location.href。这是一个重定向(GET方法),当然,POST数据不发送 尝试在setTimeout中使用
setTimeout(function() {
$("#loginform").submit();
}, 2000);
我已经测试了你的代码很多次,并得到了原因 表单提交后,页面将导航到另一个页面。现在,如果
2s
(根据您的代码)在导航发生之前通过,那么2s之后必须出现的js代码将不会执行,因为浏览器中加载了新的页面内容
因此,我尝试缩短超时时间,并获得了允许的最大值300-400。但这也不确定。因此,理想情况下,您应该将它保持在尽可能低的水平,以避免出现这种情况。如果您正在进行登录检查,您应该进行一个AJAX调用,如果凭据正确,该调用将用户存储到您保存的会话中,然后,如果AJAX返回成功,你应该重定向到另一个页面
模拟服务器检查(setTimeout)和真实服务器检查(例如AJAX调用)之间的区别在于,您可以在后者中使用回调函数,而在前者中,您不知道在2SEC中会发生什么。setTimeout()的目的是什么。?你为什么要用它?你能说出你预期会发生什么吗?在步骤中,如1、2、3…我正在使用模拟“检查服务器”,希望单击“登录”,表单数据将发送到“登录验证”。保持setTimeout是否要在setTimeout之后(即2000ms之后)发送从html表单收集的数据?这可能会起作用,但它是一个无休止的循环。测试:porta:8520 Pass:999237432020他必须将数据发送到“登录atentica”。我想这是他想要的,这就是我要回答的。
setTimeout(function() {
$("#loginform").submit();
}, 2000);