如何将JS值传递给PHP参数[重复]

This question already has an answer here:

In the code added here, I pass on value from PHP parameter to JS parameter: Both parameters are called 'stv'.

I wonder how do I do the exact opposite?

Thanks!

<script>
var stv="<?php echo $stv; ?>";
</script>

</div>

send a request with ajax using jquery if using jquery already in document. If you don't have Jquery added, you can add it ath the end of your html body using a script tag and getting the download adress from google:

<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
</body>


  function ajax(value) {
        var x = {
            'info': value //data to send can be json or something else
        };
        $.ajax({
            url: 'index.php', //page where to send
            type: 'POST', //type of request
            data: x, // data to send
            success: function(data) { //what happends when request is success 
                try {
                    getAjPromise(JSON.parse(data));
                } catch (e) {
                    console.log("error");
                }
            }
        });

    }

in PHP you check if there is a $_POST['info'], get the value and do something

</div>