发布表单,等待十秒钟并重定向到
Post form, wait ten seconds and redirect to
我有一个页面需要执行以下步骤:
步骤 1 - 通过POST
接收 URL 地址、名称、值、编号和 ID
第 2 步 - 等待 10 秒
第 3 步 - 将(也通过邮寄)通过邮寄收到的以下信息发送(也通过邮寄):名称、值、数字和 ID 到通过邮寄收到的 URL
步骤4 - 重定向到收到帖子的URL,然后在屏幕中打印帖子。
为此,我使用了下面的代码,但是出现了任何问题,因为重定向URL中的打印应该带来帖子信息是空的,所以看起来由于任何原因信息都没有正确发布。
有人可以告诉我我做错了什么吗?
法典:
HTML - 创建要发布的表单:
<form id="ret" name="return_url" method="post" action="<?php print_r($_POST['url']);?>">
<input type="hidden" name="name" value="<?php print_r($_POST['name']);?>" />
<input type="hidden" name="value" value="<?php print_r($_POST['value']);?>" />
<input type="hidden" name="num" value="<?php print_r ($_POST['num']);?>" />
<input type="hidden" name="ID" value="<?php print_r($_POST['ID']);?>" />
<input type="hidden" name="status" value="OK" />
</form>
将发布的 url 内容添加到将在 Javascript (PHP) 中使用的 var $retorno
:
<?php
$retorno = $_POST['url'];
?>
启动计数器,提交表单并重定向(使用javascript):
<script language="javascript" type="text/javascript">
window.onload = function() {
function countdown() {
if (typeof countdown.counter == 'undefined') {
countdown.counter = 10; // initial count
}
if (countdown.counter > 0) {
document.getElementById('count').innerHTML = countdown.counter--;
setTimeout(countdown, 1000);
}
else {
document.getElementById("ret").submit();
location.href = '<?php echo $retorno?>';
}
}
countdown();
};
</script>
你的代码有很多问题。
1.您在应该使用echo
的地方使用print_r
<form id="ret" name="return_url" method="post" action="<?php print_r($_POST['url']);?>">
在上面的行中,print_r
将以无效的方式输出$_POST['url']
的内容,该内容将作为action
属性值无效。查看生成的页面的 HTML 源代码。
这应该重写为:
<form id="ret" name="return_url" method="post" action="<?php echo $_POST['url']; ?>">
你对所有输入值都犯了同样的错误。操作值尤其重要,因为它必须是表单发布地址。
2. 您提交表单,但也重定向页面
表单submit()
和重定向之间存在冲突location.href
只需删除location.href
线即可。如果您的 HTML 表单配置正确,JavaScript submit()
会将浏览器发送到 action
属性中定义的页面。
最后,我建议您查看jQuery库以使JavaScript编码更容易。
相关文章:
- 通过javascript重定向html传递php变量
- JavaScript下拉菜单-点击按钮并根据所选值重定向到url
- 使用angular重定向到html页面
- 如何在chrome扩展中重定向到html页面
- 无法从jquery Mobile导航栏重定向到另一个页面
- 在 n 秒内重定向并传递值
- 页面加载上的加载模式&5秒后重定向
- javascript:检查鼠标是否按下并从零开始计数,x秒后重定向
- onClick在5秒后重定向到一侧
- angular$timeout在3秒后重定向
- yii-如何在10秒后重定向
- 使用 JavaScript 等待 X 秒后进行页面重定向
- MVC在暂停四秒后重定向到另一个页面
- Angularjs的ng-click在秒点击时重定向
- 在1秒内重定向setinterval或停止setinterval的条件
- 如果没有操作,15秒后重定向页面
- 5秒后重定向,但只允许引荐来源网址访问该页面
- 在n秒后不断重定向
- 在空闲/不活动60秒后重定向用户
- 如何每10秒重定向一个页面