Several Methods for passing parameters from php to js functions and phpjs Functions

Source: Internet
Author: User

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.

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.