Several Methods for passing parameters from php to js functions and phpjs Functions
<? Php echo "<script> test ('$ _ POST [userid]'); </script>";?>
The above $ _ POST [''] can also be applied to $ _ SESSION [''];
<? Php $ para = "hello boby! "; Echo $ para; echo" <script> var para = \ "$ para \"; alert (para); </script> ";?>;
How can I input a php variable as a parameter to the js method?
<Script>
Function show (str ){
Alert (st );
}
Show ("<? Php echo $ value;?> "); // Output the php variable value to the parameters of the JS function call;
</Script>
Passing the value of js function parameters between js and php
In this way, you use js variables in php. This is not feasible and cannot be implemented.
First of all, you need to understand that php scripts are compiled for the first time. After php is compiled, html and javascript will be executed.
I think your requirements can be implemented without javascript. You can use get/post to transmit the value of this sid. If you want to update the sid, you need to use ajax asynchronous implementation.
Long-winded:
Php variables can be used in js, but not vice versa.