首页 > 解决方案 > 调用一个新的 PHP 页面并传递一个长文本

问题描述

我有一个 PHP 页面(主),想在鼠标单击时调用另一个 PHP 页面(打印页面)。我需要传递一个大文本。

我不想将它作为 url 参数传递,因为它太大了。我想我想将它作为 ajax 传递,但我想打开打印页面,以便可以在浏览器中打印它。

I started with this but the paramater will be too big
    $('#MyModal .print').click(function() {
        var   run = "../js/print.php?ref="+ref;
        win = window.open(run, '_blank');
        win.focus();
    });

我对ajax语句很熟悉,但没有习惯打开新页面。

标签: javascriptphpajax

解决方案


您可以使用带有 a 的不可见表单target="_blank"method="post"提交它,从而在新窗口中发送 POST 请求:

<form name="printForm" style="display: none;" action="../js/print.php" method="post" target="_blank">
  <input type="hidden" name="ref">
</form>
$('#MyModal .print').click(function() {
  document.forms.printForm.ref.value = ref
  document.forms.printForm.submit()
})

然后你得到refPHP 中的值$_POST['ref']


推荐阅读