PHP 在 URL POST 上打开一个新选项卡



我看了大约 100 个问题,找不到这样的东西,如果有,我深表歉意!

我正在用PHP在wordpress网站上发布:

if(!empty($_POST)){
a bunch of stuff that all works
postUrl =  'https://services/?parameters'; //this works too!
}
get_header();
?>
<div stuff that all displays correctly>
<div class="form-row">
<input type="submit" value="Submit" name="submit">
</div>   
<? php 
$servicePost = wp_remote_post( esc_url_raw($postUrl));  //This is the problem URL
echo "<script>window.location=$servicePost;<script>";
?>

提交时,它会运行一堆 API 调用,所有工作,甚至$servicePost发布帖子。但是该URL的服务$postURL,在一个好的POST中,应该自动重定向到一个URL(发布到它,它返回一个"302"和"位置:https:ActualLaunchURL"(。
我需要将该服务重定向到浏览器中的新选项卡。

现在,我认为正在发生的事情是,当$servicePost进行实际调用时,POST 会填充,当它到达 JS 窗口时.open 它不再是 POST,并且不会使用 window.open 命中服务。

问:我可以制作一个 POST,并在调用运行时打开一个新选项卡,在该 <\script> 窗口中打开吗?

我也试过:

<script type="text/javascript">  
var form = document.createElement('FORM');
form.method='POST';
form.action = $ampssoData;
form.target = '_blank'; 
document.body.appendChild(form)
form.submit();
</script>

在提交后的 HTML 中,这甚至没有发布,所以我

所以我找到了如何: 在 PHP 文件中为 Wordpress 制作一个 POST, 打开一个新选项卡, 将 PHP URL 变量发布到服务

事情是这样的:

if(!empty($_POST)){
a bunch of stuff that all works
postUrl =  'https://services/?parameters'; //this works too!
}
get_header();
?>
<div stuff that all displays correctly>
<?php if: 
<div class="form-row">
<input type="submit" value="Submit" name="submit">
</div>   
<? php 
$servicePost = wp_remote_post( esc_url_raw($postUrl));  //This is the problem URL
echo "<script>window.location=$servicePost;<script>";
?>

这是正确的底部:

if(!empty($_POST)){
a bunch of stuff that all works
postUrl =  'https://services/?parameters'; //this works too!
}
get_header();
?>
<div stuff that all displays correctly>
<div class="form-row">
<input type="submit" value="Submit" name="submit">
</div>   
<?php else: ?>
<script type="text/javascript">
function openWindowWithPost(url){
var form = document.createElement('form');
form.method='POST';
form.action = url;
form.target = '_blank';
document.body.appendChild(form);
form.submit();
}
</script>
<script type="text/javascript">
openWindowWithPost("<?php echo $postUrl; ?>");
</script>  

它从 PHP 变量中获取数据,并在 PHP 文件的 HTML 部分中进行调用。它第一次触发了弹出窗口阻止程序,但在其他方面有效!
如果有人能告诉我如何不触发它,如果可能的话,那就太酷了!

相关内容

最新更新