Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Jun 2005
    Location
    Florida
    Posts
    73
    Thanks
    11
    Thanked 0 Times in 0 Posts

    Using a Javascript variable with PHP

    In the code below, the page is stored in the text variable. I would like to use that variable on the save-rpt.php page targeted in the script. I know that there are ways to use a javascript variable in php using the $_GET method but I don't think that would work for me in this case. What would be the best way to pull the value of text for use in php?

    Code:
    <script type="text/javascript">
    		function saveDocument() {
    			text = document.body.innerHTML;
    			document.getElementById("response").style.display = "block";
    			advAJAX.post({
    				url: "/includes/save-rpt.php",
    				parameters : {
    				  "text" : text,
    				  "name" : "<?php $_SESSION['username']; ?>"
    				},
    				onSuccess : function(obj) { document.getElementById("response").innerHTML = obj.responseText; },
    				onError : function(obj) { alert("Error: " + obj.status); }
    			});
    		}
    </script>

  • #2
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,536
    Thanks
    80
    Thanked 4,490 Times in 4,454 Posts
    Your choices are $_GET and $_POST.

    Since you are using advAJAX.post I would assume that your "save-rpt.php" code would need to use $_POST. Never seen that particular method of callling AJAX, but I would assume that .post( ) leads to $_POST. I'd assume that if you had used advAJAX.get( ) that *then* you would use $_GET.

  • Users who have thanked Old Pedant for this post:

    thepocketgeek (05-25-2009)

  • #3
    New Coder
    Join Date
    Jun 2005
    Location
    Florida
    Posts
    73
    Thanks
    11
    Thanked 0 Times in 0 Posts
    Thanks. I will try $_POST and see if that works.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •