Skip to content
Advertisement

how to pass JavaScript value to PHP page

It is showing undefined function in PHP page.And i made every possible way it is not working for me.Please guys help me with this.

<!DOCTYPE html>
<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
    </head>
    <body>
       <div id="myDiv">Welcome to stackoverflow</div>
    </body>
    <script>
       $(document).ready(function(){
            var mb = $('#myDiv').text();
            $.ajax({
                action : "six-cuf.php",
                type: 'POST',
                data: { 'mb': mb},
                success:function(data)
                {
                    alert(mb);   
                }
            });
        });
    
    </script>
</html>

PHP CODE

<?php  
  $fname = $_POST['mb'];
?>

Advertisement

Answer

Hello
$(document).ready(function(){
  var mb = $('#myDiv').text();
  $.ajax({
    action : "six-cuf.php",
    type: 'POST',
    data: { mb: mb},
    success:function(data)
    {
      alert(mb);   
    }
  });
});
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement