Can i pass the javascript variable to php variable..like this..
var canvas = document.getElementById("canvas");
var data = canvas.toDataURL("image/png");
var newImg = document.createElement("img"); // create img tag
newImg.src = url;
var can = document.body.appendChild(newImg);
<?php
$canvas = "<script>document.write(can)</script>";
echo $canvas;
?>
Is possible to pass that javascript variable to php variable ?
bayblade567
3762 silver badges11 bronze badges
-
possible duplicate of How to pass JavaScript variables to PHP?D4V1D– D4V1D2015年03月29日 06:48:53 +00:00Commented Mar 29, 2015 at 6:48
1 Answer 1
"You cannot pass variable values from the current page JavaScript to the current page PHP code... PHP code runs at the server side and it doesn't know anything about what is going on on the client side." - How to pass JavaScript variables to PHP?
Basically, your PHP will run first, then the HTML page will be rendered with the JavaScript.
answered Mar 29, 2015 at 6:49
Drakes
23.8k3 gold badges58 silver badges97 bronze badges
Sign up to request clarification or add additional context in comments.
3 Comments
CuriousMind
This ideally suites for comment and not as answer.
Drakes
"Is possible to pass that javascript variable to php variable?" - He asked about that variable 'can' and I answered. He can ask another question about different ways to accomplish something similar if he likes.
Evan Carslake
Agreed as well, answered the question that was asked. Then gave extra information. Just because extra information was included, does not make it a comment of subject.
default