0

This is the situation: I have 2 files, reportCaller.php and report.php. From the reportCaller.php, the user is going to press a button with the method "onclick", this will call the function that is going to do the ajax/post stuff (this is with what im having problems), report.php is going to catch some parameters by POST and has to be opened on a new Tab or Window, this is going to display a report. (Note: May be not important, but im using 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();
    });

}

report:

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

Thanks for reading.

  • show us what you have tried. Its hard to understand what you are trying / doing based on what you have provided. – floor Mar 11 '15 at 16:16
  • If the answer provided doesn't help. Try looking here http://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-using-javascript – floor Mar 11 '15 at 19:37
  • I know how to open urls in new tabs and windows. The problem is that i need to send data throught post method to that url. – Jose Caballero Preciado Mar 11 '15 at 20:08
  • I don't quite understand. Is your ajax call not working properly? – floor Mar 11 '15 at 21:22

1 Answers1

2

This is more of a comment than an answer, but I haven't got the reputation ;-)

take a look at Javascript Post on Form Submit open a new window

the trick is to put your button in a

<form target="_blank">

Element and then send that form..

You could do your processing of data in the onsubmit Handler

Community
  • 1
  • 1