【发布时间】:2018-08-13 05:53:52
【问题描述】:
我想检查 php 中的变量是否具有活动值 我这样测试但不起作用
我在 check.php 中有这个变量
$status = 'active';
我在 javascript 文件中有这个
$.ajax({
type: "POST",
url: "check.php",
success: function(check) {
var statusJS = '<?php echo $status; ?>';
if (check[statusJS] == "active" {
alert("status : active");
}}})
这个完整的 check.php 文件
<?php
$status = 'active';
$gpa = 'html data here';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
echo $gpa;
echo $status;
} else {
include("gp-e.php");
}
?>
是否可以在 javascript 中从 php 获取变量值而不在 php 文件中回显它?
【问题讨论】:
-
检查
var_dump($status)和console.log(check,check[statusJs]) -
我真的不明白我将把它放在 php 或 javascript 中的哪个位置,但我在 javascript 中测试它但在控制台中未定义
标签: javascript php ajax post get