情况是这样的:我有2个文件,reportCaller.php和report.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/