Answers for "how to pass php variable value in jquery function"

PHP
8

php pass a variabele to js

<script>
'var name = <?php echo json_encode($name); ?>;
</script>'
Posted by: Guest on February-08-2020
-1

how to use jquery variable in php

Try this one:

<html>
<head>
<script src="jquery.js"></script>
<script>
$(document).ready(function(){
  var id = 23; 
$("#submit").click(function(){
 $.ajax(
    {
    url: "B.php",
    type: "POST",

    data: { id1: id},
    success: function (result) {
            alert('success');

    }
});     
   });
  });
 </script>
 </head>
 <body>
 <form  >
 <input type="button" id="submit" name="submit"/> 
 </form>
 </body>
 </html>
Then B.php

<?php
   $a =isset($_POST['id1'])?$_POST['id1']:'not yet';
   echo $a ;
   ?>
Posted by: Guest on July-13-2021

Code answers related to "how to pass php variable value in jquery function"

Browse Popular Code Answers by Language