我的PHP
文件以
<?php
$tm = new TeamManager();
?>
<script type="text/javascript">
var team = <?php echo json_encode($tm->GetWholeTeam()); ?>;
</script>
其余部分未被阅读,原因不明。我已将其缩小到第<?php echo json_encode($tm->GetWholeTeam()); ?>
行,但即使添加
error_reporting(-1);
ini_set('display_errors', 'On');
到脚本的顶部。作为参考,我的TeamManager
类在
<?php
// Gets included in functions.php
final class MySqlInfo
{
const TEAMTABLENAME = 'mems';
const PROJSTABLENAME = 'projs';
public static function getTeamTableName ( )
{
return self::TEAMTABLENAME;
}
public static function getProjectsTableName ( )
{
return self::PROJSTABLENAME;
}
}
final class MethodResult
{
public $succeeded;
public $message;
public function MethodResult ( $succeededInit = NULL, $messageInit = NULL )
{
$this->$succeeded = $succeededInit;
$this->$message = $messageInit;
}
}
final class TeamMember
{
public $name; // team member name
public $title; // team member title
public $bio; // team member bio
public $sord; // team member sort order
public $picfn; // team member profile picture file name
public function TeamMember ( $name_init, $title_init, $bio_init, $sord_init, $picfn_init )
{
$this->name = $name_init;
$this->title = $title_init;
$this->bio = $bio_init;
$this->sord = $sord_init;
$this->picfn = $picfn_init;
}
}
final class TeamManager
{
public function TeamManager ( )
{
// ....
}
public function addMember ( TeamMember $M )
{
$q = "INSERT INTO " . MySqlInfo::TEAMTABLENAME . " (" . implode( ',', array($M->name, $M->title, $M->bio, $M->sord, $M->picfn) ) . ") VALUES ('" . implode('\',\'', array($_POST['fullname'], $_POST['title'], $_POST['bio'], $_POST['sord'], $targetFileName)) . "')";
// ^ query for inserting member M to the database
if (!$wpdb->query($q))
{
return new MethodResult(false, 'Query to insert new team member failed');
}
// else
return new MethodResult(true, 'Successfully added new member' . $M->name);
}
public function getWholeTeam ( )
{
$q = "SELECT name,title,bio,sord,picfn FROM " . MySqlInfo::TEAMTABLENAME;
$teamRows = $wpdb->query($q);
return $teamRows;
}
}
?>
但我也没有在该页面上收到任何错误。我还通过在线PHP
验证器运行所有内容,并且不会出现任何错误。是什么给了什么?
答案 0 :(得分:0)
试试这个:
<?php
$tm = new TeamManager();
?>
<script type="text/javascript">
var team = JSON.parse('<?php echo json_encode($tm->GetWholeTeam()); ?>');
</script>