dpizd08264 2013-01-18 15:19
浏览 129
已采纳

jQuery - 在iframe完成加载后将数据发布到iframe并重定向

Here is what I have so far:

<?php

// Simulating some post values for test proposes
$_POST['test'] = 'testing values';

// POST contents (originally from a form in another page)
$query = http_build_query( $_POST );

?>
<!DOCTYPE HTML>
<html>
<head>
 <meta http-equiv="content-type" content="text/html" />
 <script src="http://code.jquery.com/jquery-latest.js"></script>
 <script type="text/javascript">
  $(function() { $("#myiframe").load(function(){ window.location.replace('after.php'); }); });
 </script>
 <title>iFrame Load POST</title>
</head>
<body>
<iframe id="myiframe" src="load.php" width="0" height="0"></iframe>
</body>
</html>

What I need is to be able to send $_POST data, originally sent from a form in another page, to the iframe and redirect the page after the iframe has loaded and processed the post data.

---- EDIT ----

In fact, it doesn't need an iframe, but I still need to do a post call to load.php and wait for it to load in order to make the redirect. I cannot redirect before the load.php has finish loading the request. That's why I was using the iframe method and previously using GET instead of POST.

--------------

Can someone please help?

Thank you!

  • 写回答

1条回答 默认 最新

  • duanlipeng4136 2013-01-18 15:31
    关注

    Just use a jQuery AJAX call. It allows you to attach a handler that gets executed once the request finishes successfully.

    $.ajax({
        url: 'load.php',
        data: {foo: 'bar'},
        type: 'post', // you can use get if you want to.
        success: function(response) {
            window.location.replace('after.php'); 
        }
    });
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?