我想在我的javascript代码中调用php函数,但我得到了一个sytax错误

I want to make a call to a php function within my javascript code, but I get a sytax error

本文关键字:错误 sytax 一个 javascript 我的 代码 函数 php 调用      更新时间:2023-09-26

POST_manip.html:

<script type="text/javascript">
            // get the post vars
            var $_POST = <?php echo json_encode($_POST); ?>;
            document.write($_POST);

我只是想用javascript操作post-var,但首先,我需要这些var,php是唯一的方法。

json_encode返回一个有效的js对象,而不是字符串,因此您可以将js$_POST作为常规对象访问。

html文件在您的服务器中是通过PHP解析的吗?尝试将文件扩展名更改为.php

您可以使用console.log($_POST(和类似firebug的东西而不是document.write((来检查变量内容