繁体   English   中英

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

[英]jQuery - POST data to iframe and redirect after iframe has finish loading

这是我到目前为止的内容:

<?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>

我需要的是能够将最初从另一个页面中的表单发送的$ _POST数据发送到iframe,并在iframe加载并处理过数据后重定向页面。

----编辑----

实际上,它不需要iframe,但我仍然需要对load.php进行后期调用,并等待其加载才能进行重定向。 在load.php完成加载请求之前,我无法重定向。 这就是为什么我使用iframe方法并且以前使用GET而不是POST的原因。

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

有人可以帮忙吗?

谢谢!

只需使用jQuery AJAX调用即可。 它允许您附加一个处理程序,该处理程序将在请求成功完成后执行。

$.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'); 
    }
});

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM