2013-01-18 21 views
0

这里后,我到目前为止有:jQuery的 - POST数据到iframe和重定向的iframe具有完成加载

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

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

是否有人可以帮忙吗?

谢谢!

+0

为什么你需要在iframe中完成文章,如果你只是打算在请求完成后重定向(即你没有对你刚刚加载的内容做任何事情)?您是否试图绕过跨域问题?如果没有,一个普通的AJAX调用就可以做到。 –

+0

可以这样,是的,事实上iframe是不需要的。 – BornKillaz

+0

一切都在同一个域上。 – BornKillaz

回答

2

只需使用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'); 
    } 
});