Transfer data between JavaScript and PHP through JSON



PHP Snippet 1:

<!-- change your button -->
    <button type="button" onclick="registroModificacion()">Convert</button>><
<!-- add at the end of yout page. you have to use jquery library -->
    <script src="https://code.jquery.com/jquery-3.5.1.min.js" ></script>
    <script>
        function registroModificacion(){
            //get values of your form by id
            const needed = $('#needed').val();
            const usd= $('#usd').val();
            $.ajax({
              url:'paginaEn.php',
              type:"POST",
              data: {needed:needed,usd:usd},
              success:function(r){
               alert(r);
              },
            })
        }
    </script>

PHP Snippet 2:

<?php
    $usd= $_POST['usd'];
    $needed= $_POST['needed'];
    echo $needed." ".$usd;
?>