How to capture a Javascript function's return value into a PHP variable?
Example:
Javascript: javascriptFunction { return null;};
PHP: $php_variable = javascriptFunction();
If clarification is needed, please let me know.
-
Yes... what is it exactly that you're trying to do?jeremy– jeremy2013年08月17日 01:53:44 +00:00Commented Aug 17, 2013 at 1:53
3 Answers 3
JavaScript runs on the client side, while PHP runs on the server side. As such, you cannot execute JavaScript code inside your PHP code; however, these two components can communicate via several channels including:
The easiest approach would be to set a query parameter on your URL: example.com/?variable=value and access it from your PHP script using, $_GET['variable'].
Hope this helps.
Comments
Without any idea of what you're trying to do...
Use jquery (with ajax):
$.get("test.php", { name: "John", time: "2pm" } );
Where test is the php file you're sending data to, and John and 2pm are the data.
Then in test.php do:
$name = $_GET['name']
and do the same for time!
Comments
You would have to AJAX the value to the server and pull it from $_GET or $_POST:
$.ajax({type:"get", data:javascriptFunction(), url:script.php });
Then, simply use $value = $_GET.