Form not submitted properly to the right page when

2019-07-14 22:24发布

问题:

I want to open a new window (not tab) on button click and pass arguments to the new page opened in the new window.

My SO search took me to this answer, and I followed it. I am facing the following problems:

  1. The new window that opens does Not get the title of the page from the HTML <title> tag in secondIndex.php.

  2. The data I am trying to pass in the hidden input field of the form does not seem to be passed to the page opening on button click.

  3. The newly opened page should have the URL like http://something/something/secondIndex.php because that is the value of the action attribute in the form tag. But it rather says about:blank.

The question is why, where am I going wrong, and how do I fix these problems?

index.php:

<?php

$dataToPass = array(
        "A" => array(
                1 => array(
                        "id" => 1,
                        "secondId" => 2,
                        "thirdId" => 3
                )
        ),


        "B" => array(
                1 => array(
                        "id" => 4,
                        "secondId" => 5,
                        "thirdId" => 6
                ),
                2 => array(
                        "id" => 7,
                        "secondId" => 8,
                        "thirdId" => 9
                )
        ),


        "C" => array(
                1 => array(
                        "id" => 10,
                        "secondId" => 11,
                        "thirdId" => 12
                )
        )

);


?>

<!DOCTYPE html>

<html>

<head>

<script src="jquery.min.js"></script>

<script src="scripts.js"></script>

</head>







<body>


<form id="aForm" action="secondIndex.php" method="post" target="TheWindow" >
    <input type="hidden" name="hiddenData" value="<?php echo json_encode($dataToPass); ?>" />
</form>



<button id="aButton">Click Me</button>

</body>

secondIndex.php:

<html>

<head>
    <title>Data</title>
</head>

<body>
    <?php 

        if (isset($_POST["hiddenData"])) {
            print_r($_POST["hiddenData"]);
        }

    ?>
</body>

</html>

scripts.js:

$(document).ready(function() {

    $("#aButton").click(function() {
        alert("#aButton clicked.");//check

        window.open("", "TheWindow", "width=500px, height=500px");
        document.getElementById("#aForm").submit();
    });

});