0

How can I pass the value of a php variable to an AJAX request? I'm using sessions here, started in another php file (header.php). The variable is "$_SESSION['name']", and I want to pass as a parameter instead of "XXX" (the function is called by a button).

<?php include("header.php"); ?>
<script>
function sendFunc()
            {
                var message = document.getElementById('msg_text').value;
                new Ajax.Request("chat_room_insert.php",
                    {
                        method: "post",
                        parameters: {id: 0, name: "XXX", msg_text: message},
                        onSuccess: function() {},
                        onFailure: function() { alert("failure"); },
                        onException: function() { alert("exception"); }
                    });
            }
        </script>
Lorenzo
  • 47
  • 8

1 Answers1

-1

Change

parameters: {id: 0, name: "XXX", msg_text: message},

to

parameters: {id: 0, name: "<?= $_SESSION['name'] ?>", msg_text: message},
Robert
  • 19,800
  • 5
  • 55
  • 85