Good day, experts! =)
In general, I looked at a bunch of materials about the transfer of a variable from js / jqwery to PHP, all of these materials explained that this is not a trivial task, a bunch of lines of code were cited as an example, for example (some wild methods, libraries lines 25-100 of the code) ...
And today, at 3:30 in the morning, sitting at the solution of the next problem, a related issue, and after drinking a couple of bottles of delicious beer, it “dawned on me” -
Why write all this unnecessary code from the examples, when everything can be done so simply that I did not believe myself that it would work at all. In short, the doubt has crept in that it will work out at all, but as it turned out, everything ingenious is simple ... Here is the code for the actual thing that occurred to me:
<script> var peremennayaJs= 1; <?$peremennayaPhp="peremennayaJs";?>; alert(<?echo $peremennayaPhp;?>); </script> I was very surprised that it worked, initially skeptical that it was coming in a drunken stupor, but no ...
That doubt has crept in, maybe I missed something, I can not do it for some unclear reasons. Simply, I program I can say the first month, and then only procedural programming in PHP, c js just starting to look at the simplest things.
I ask you not to throw stones if this is trivial, and I now share what everyone knows as 2 + 2 ... Just then why are you misleading that the transfer of the value of the variable js to php is PPC as difficult ?!
In general, the question is how permissible? Is it possible to use it, are there any pitfalls?
var peremennayaJs=1at the exit to the alert and not with php. Now I will write in the answer in detail why this is happening - Mr. Black