T
T
TechNOIR2018-04-13 19:17:55
PHP
TechNOIR, 2018-04-13 19:17:55

php+js. Is it possible to return a variable from JS to PHP inside one script?

Good afternoon.
Please tell me about the backfill question)
In general, there is a script (script.php) that looks something like this:

<?php
----текст php кода----
?>
<html>
<script>
----текст js кода----
<script>
----текст html кода----
</html>

The scheme is something like this. PHP code is executed, it transfers values ​​to html, js code is executed in html and a variable $temp appears in the js code. How can this variable be returned to php?
The script is cyclic. The bottom line is that according to the data from php, html draws 3 buttons, each button corresponds to a link. After clicking the button, you need to understand what the link is behind the button and pass it back to php For the record ...
Just don't throw stones, I'm still a beginner)
Thanks in advance)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yan-s, 2018-04-13
@Yan-s

No.
PHP runs on the server, JS in the browser on the user's computer. (in your case)
If you formulate the task in more detail, I can suggest how it can be solved.

P
Pantene742, 2018-04-13
@Pantene742

PHP Works in tandem with Apache and Apache waits for php to generate an entire page to send it to the server.
and generally generate JS code using PHP Returning it to the page in echo is an extremely stupid crutch.
If you need to exchange data between the client application and the server, there is Ajax for this. This is when some part of the code on the page makes a request to the server and requests not the whole page, but data, and can also send it in the request. Read about the http protocol, how php works.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question