Skip to content
Advertisement

call a new PHP page and pass a long text

I have a PHP page(main) and would like to call another PHP page(printpage) on mouse click. I need to pass a large text.

I do not want to pass it as a url parameter as it will be too big. I guess I want to pass it as an ajax but I want to open the printpage so I can print it in the browser.

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();
    });

I am familar with the ajax statement but have not used to open a new page.

Advertisement

Answer

You can use an invisible form with a target="_blank" and method="post" and submit it, thereby sending a POST request in a new window:

<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()
})

Then you get the ref value in PHP as $_POST['ref']

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement