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

标签 javascript php jquery ajax

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

报告调用者 (HTML):

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

报告调用者(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 Post on Form Submit open a new window

诀窍是将按钮放在

<form target="_blank">

元素然后发送该表单..

您可以在 onsubmit 处理程序中处理数据

关于javascript - 使用 POST 打开新选项卡或窗口 [PHP],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28991119/

相关文章:

javascript - 正确输入文本后,图像会亮起/变化

PHP Zip 文件为空?

javascript - 当元素不存在时使用 .on() 的 Jquery 在 ios7 上不起作用

javascript - jQuery - 从处理函数接收正确的变量值

javascript - jVectorMap 无法检索 map 对象

javascript - mvc回发后AngularJS空输入模型

php - 如果结果匹配,则将 MySQL 结果限制为一个

javascript - AJAX 在 Safari 或 Safari 移动设备中未触发

JavaScript getMonth() 返回月份值 50

javascript - jQuery:以前的子级和类名