JS calls the variables in PHP, how do you get it?

Source: Internet
Author: User

js call PHP variables, how to get the example on the Web is a JS file in the beginning to give this variable a value, if that is what the meaning of Ah, I want is can change. hychyc_2008 | browse 2,741 times 2013-04-18 12:24 2013-04-20 10:34Best Answer
<script>
var str=<?php echo $value;? >
</script>
This practice I used before, some browsers can, some browsers will not recognize. Specific is IE several I forget ~ ~ ~
It seems that IE6 didn't recognize it.
My approach is to:
<?php

echo "
<script>
var str= $value;
</script> ";

?>
This is sure to be fine.
This answer is recommended by the questionerComments (1)0

Front_diablo

Adoption Rate: 37% good: Not customized

Other answersvar str=<?php echo $value;? > is assigning values directly to variables. If JS is an external file, can be written in the form of a function, called when the parameters are assigned to PHP, such as AA (<?php echo $value; >)Miss Oba 芓 | 2013-04-18 13:18 Reviews2 1
123456 <scripttype="text/javascript">if(str==<?phpecho $str;?>){    alert(3333333333);}</script>
Mbseo | 2013-04-18 12:45 Reviews0 0 This is not allowed, PHP is the server-side compiler language, JS is the browser-side interpretation language. Zuoyiduohua | 2013-04-18 12:38 Reviews0 3 then you get it dynamically with Ajax .123010wqq | 2013-04-18 12:29 Reviews0 0 var str=<?php echo $value;? >zhx626 | 2013-04-18 12:27

JS calls the variables in PHP, how do you get it?

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.