Home >Backend Development >PHP Tutorial >Several ways for php to pass parameters to js functions, several ways for phpjs functions_PHP tutorial
<?php echo "<script>test('$_POST[userid]');</script> "; ?>
The $_POST[''] above can also be applied to $_SESSION[' '];
<?php $para = "hello boby!"; echo $para; echo "<script> var para=\"$para\"; alert(para);</script>"; ?>;
3f1c4e4b6b16bbbd69b2ee476dc4f83a
function show(str){
alert(st);
}
show("eb4bd62954e83d68558dfe15e6d196b2");// Output the value of the php variable into the parameters of the JS calling function;
2cacc6d41bbb37262a98f745aa00fbf0
What you are doing is using JS variables in PHP, which is not feasible and impossible.
First of all, you must understand that the PHP script is compiled immediately, and the compilation is completed. Only PHP can execute HTML and JavaScript.
I think your requirement does not require JavaScript. You can use get/post to pass the value of your SID. If you want no refresh, you need to Use ajax asynchronously to achieve it.
Just a moment:
You can use php variables in js, but not vice versa