php passes data to javascript

WBOY
Release: 2016-07-29 08:59:20
Original
1589 people have browsed it

It is very important for php to pass data to javascript. I think it is very necessary for us to send data through php, but how to pass php data to js has made me think for a long time and search for it on the Internet for a long time, but In the end, I really felt like I was looking back at the scene, and that person was there in the dim light. It really wasn't that small of a difficulty. Below we use an example to explain the method of passing data from php to js. Of course, these are all in the same interface. The first method is to pass a string, and the second is to pass an array,







$para ="hello body";//Define a string
echo "<script>var para="$para"</script>";//Pass it to javascript
?>

$hello=array('1','2','3');//Create an array,
$hellojson=json_encode($hello) ;And change the array into json format
echo <<
eot

// These codes implement the transfer of arrays from php to js.
?>



The above introduces how PHP transfers data to JavaScript, including aspects of it. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!