【发布时间】:2014-04-29 14:20:07
【问题描述】:
我正在使用 ajax POST 调用函数,然后尝试访问类中的对象,但由于某种原因,我在调用类函数后得到了 NULL
这是我的代码
include_once dirname(__FILE__).'/../db/_mysql.php';
include_once dirname(__FILE__).'/../class/door.php';
$db = new _mysql();
if (isset($_POST['door'])) {
if ($_POST['door'] == 'get-default') {
$doors = array();
for ($i = 0; $i < $_POST['amount']; $i++) {
array_push($doors, array(
'door-id' => $i,
'panel-colors' => 'valkoinen'
)
);
}
order_door::setDoors($doors);
}
if ($_POST['door'] == 'get-doors') {
print_r(order_door::getDoors());
$doors = order_door::getDoors();
if ((int) $_POST['total-count'] > count($doors)) {
echo $_POST['total-count'] . '>' . count($doors);
} else if ((int) $_POST['total-count'] < count($doors)) {
echo $_POST['total-count'] . '<' . count($doors);
}
}
}
class order_door {
private static $doors;
public static function getDoors() {
return self::$doors;
}
public static function setDoors($array) {
if (count($array) == 0) {
self::$doors = array();
} else {
self::$doors = $array;
print_r(self::getDoors());
}
}
}
在第二个 ajax 调用中,我试图访问 get-doors 在 POST get-doors print_r(order_door::getDoors());没有打印任何东西。有什么想法吗?
【问题讨论】:
-
你的 ajax 请求在哪里