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 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题