Php uses $ _ POST or $ _ SESSION [] to pass parameters to js functions. _ post_session_PHP tutorial

Source: Internet
Author: User
Php uses $ _ POST or $ _ SESSION [] to pass the parameter _ post_session to the js function. Php uses $ _ POST or $ _ SESSION [] to pass parameters to js functions, _ post_session you can use $ _ POST or $ _ SESSION [] to transmit parameters to js functions in php programming. you can also use the echo statement to output and copy the data to php. use $ _ POST or $ _ SESSION [] to pass the parameter to the js function.

You can use $ _ POST or $ _ SESSION [''] to transmit parameters to js functions in php programming. you can also use echo statements to output parameters.

The code is as follows:


<? Php
Echo "script test ('$ _ POST [userid]'); script";
?>


The above $ _ POST [''] can also be applied to $ _ SESSION [''];

The code is as follows:


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


Passing parameters in JS and PHP

I think there are two methods:
First, if you get the parameter value through the get method in php:
You can directly use js to switch to the PHP file address:
Window. location. href = 'mis/vocat/service. php? Param = xx'
Second: pass the value through ajax
I am using the js Library: jquery
If you pass only one parameter param, you can directly write it as the value of param: 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 (){
// Processing required by js after php returns the corresponding data
});
})

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.

Callback can use $ _ POST or $ _ SESSION [''] to transmit parameters to js functions in php programming. you can also use echo statements to output and copy parameters...

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.