admin管理员组文章数量:1336207
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.
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.
Share Improve this question asked Aug 17, 2013 at 1:52 user2581346user2581346 1- Yes... what is it exactly that you're trying to do? – jeremy Commented Aug 17, 2013 at 1:53
3 Answers
Reset to default 3JavaScript 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 ponents can municate via several channels including:
- HTTP Cookies
- AJAX
- WebSockets
The easiest approach would be to set a query parameter on your URL: example./?variable=value
and access it from your PHP script using, $_GET['variable']
.
Hope this helps.
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!
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
.
本文标签: How to capture a Javascript function39s return value into a PHP variableStack Overflow
版权声明:本文标题:How to capture a Javascript function's return value into a PHP variable? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1742399711a2467639.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论