使用 POST 打开新的选项卡或窗口 [PHP]


Open new Tab or Window with POST [PHP]

这是这种情况:我有 2 个文件,报告呼叫者.php报告.php。从 reportCaller.php,用户将使用方法"onclick"按下一个按钮,这将调用将要执行 ajax/post 操作的函数(这与我有问题),报告.php将通过 POST 捕获一些参数,并且必须在新的选项卡或窗口中打开, 这将显示一个报告。(注意:可能不重要,但我使用 HTML2PDF)。

reportCaller (HTML):

<input type="button" onclick="generateReport()">

reportCaller (JS):

function generateReport(){
  var id = '¡I must reach the report FILE!';
  //I tried a couple stuff, but didnt work, this is one:
     $.ajax({
        type: "POST",
        url: "report.php",
        data: {id:id},
        cache: false,
        success: function (html) {
            myWindow = window.open(encodeURIComponent(true),
                "_blank");
            myWindow.focus();
    });
}

报告:

$id = $_POST['id'];
//This file (report.php) must catch $_POST, will not help if i only open the file in a new Tab/Window

感谢您的阅读。

这与其说是答案,不如说是评论,但我没有得到声誉;-)

看看Javascript 在表单上发布 提交 打开一个新窗口

诀窍是将按钮放在一个

<form target="_blank">

元素,然后发送该表单。

您可以在提交处理程序中处理数据