PHP uses $_POST or $_SESSION[] to pass parameters to js function, _post_session_PHP tutorial

WBOY
Release: 2016-07-13 10:18:49
Original
1205 people have browsed it

php uses $_POST or $_SESSION[] to pass parameters to the js function, _post_session

In PHP programming, you can use $_POST or $_SESSION[' '] to pass parameters to the js function, or you can use the echo statement for output

Copy code The code is as follows:

echo "<script>test('$_POST[userid]');</script> ";
?>

The above $_POST[''] can also be applied to $_SESSION[' '];
Copy code The code is as follows:

$para = "hello boby!";
echo $para; // www.jb51.net
echo "<script> var para="$para"; alert(para);</script>";
?>

Problems passing parameters between JS and PHP

I think there are two methods:
The first one: If you get the parameter value through php through the get method:
Just use js to redirect to the address of the php file:
window.location .href = 'mis/vocat/service.php?param=xx'
Second option: pass value through ajax
I use js library: jquery
If you only pass one parameter param is directly written as: param: value of param
If there are multiple parameters, it is written as: parameter 1: value of parameter 1, parameter 2: value of parameter 2
$(function(){
$. post('mis/vocat/service.php',{param:value},function(){
//The processing that js needs to do after php returns the corresponding data
});
})

The value of js function parameter is passed between js and php

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

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/879720.htmlTechArticlephp uses $_POST or $_SESSION[] to pass parameters to the js function, _post_session is passed to the js function in php programming You can use $_POST or $_SESSION[' '] for parameters, or you can use echo statements for output copy generation...
Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template