View Full Version : Using a Javascript variable with PHP

05-25-2009, 07:11 PM
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?

<script type="text/javascript">
function saveDocument() {
text = document.body.innerHTML;
document.getElementById("response").style.display = "block";
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); }

Old Pedant
05-25-2009, 08:29 PM
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.

05-25-2009, 10:26 PM
Thanks. I will try $_POST and see if that works.