JQuery trigger click through $ .post

I am sending data from pagex.php to y.php through a jQuery message.

pagex.php contains

$('#btn').click(function(e) {
        e.preventDefault();
        var x = 'variable1';
        var y = 'variable2';
        $.post("/pagey.php", { var1: x, var2: y}, function(data) {});
    });

pagey.php contains

<form action=....>
<input type="text" name="x" value="<?php echo $_POST['var1'] ?>" />
<input type="text" name="y" value="<?php echo $_POST['var2'] ?>" />
<input id="submit" type="submit" value="submit" />
<script type="text/javascript">$('#submit').trigger('click')</script>

So basically, when I submit the values ​​from pagex.php to pagey.php, I want to automatically submit the form to pagey.php. The jQuery line at the end of pagey.php will automatically click on the submit button. However, jQuery does not launch the submit button. it works if I access paygey.php directly (I tried it with predefined variables) but didn't execute $ .post from pagex. I assumed that using $.postfrom pagex, the page should automatically receive values ​​and run jQuery submit. What is the problem?

+3
source share
5

JavaScript ( jQuery) , . , , script, .php

0
<input type="text" name="x" value="<?php echo $_POST[var1] ?>" />
<input type="text" name="y" value="<?php echo $_POST[var2] ?>" />

<input type="text" name="x" value="<?php echo $_POST['var1'] ?>" />
<input type="text" name="y" value="<?php echo $_POST['var2'] ?>" />

.

0

URL- ... pagey, , .

- document.ready pagey...

0

, , , , ?

, .

0

, . .

<?php
    echo
    "<script type='text/javascript'>
        $(document).ready(function() {  
            $('#submit').trigger('click');
        }); 
    </script>";
?>
0

All Articles