Js混合PHP

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-20 12:43:46
Original
1533 people have browsed it

test.php<html>.....<script>    function GoEvent(id){<?php    $info=$events->getIdInfo($id);    //如何将函数的id传到php里去?>    }</script></html>
Copy after login


回复讨论(解决方案)

不可能!
php 先于 js 执行,也就是说
执行 GoEvent 时,$info=$events->getIdInfo($id); 已经执行过了

如果你需要在 GoEvent 中向 php 传值,那么请使用 ajax
但需要注意的是:http 是无状态协议,是不可重入的。每个请求都是单独执行的,你可能需要借助其他载体来缓存数据

PHP是服务器端的语言  
而js是浏览器端的 
当你的浏览器开始执行js的时候 
那段php代码已经被执行过了 
你可以做异步的请求 ajax

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
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template