POST_manip.html:
<script type="text/javascript">
// get the post vars
var $_POST = <?php echo json_encode($_POST); ?>;
document.write($_POST);
我只是想用 javascript 操作后变量,但首先,我需要这些变量,而 php 是唯一的方法。
最佳答案
json_encode 返回一个有效的 js 对象,而不是字符串,因此您可以将 js $_POST 作为常规对象访问。
.html 文件是通过服务器中的 PHP 进行解析的吗?尝试将文件扩展名更改为 .php
你可以使用console.log($_POST)和类似firebug的东西来代替document.write()来检查变量内容
关于php - 我想在 javascript 代码中调用 php 函数,但出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7122685/