所以,我有这个 PHP 文件,它将数据作为 JSON 回显:
这是这里的PHP:
// Recieved the user id:
$userId = $_POST['userId'];
// Create connection
$con = mysqli_connect("123.com", "123", "123", "123", "1234");
// Check connection
if (mysqli_connect_errno($con)) {
echo "Failed to connect to database " . mysqli_connect_error();
}
// Work with the database to grab user statistics..
$getQuizMode = "SELECT `QuizModeScore` FROM `userstats` WHERE UserId = $userId";
$getChallengeMode = "SELECT `ChallengeModeScore` FROM `userstats` WHERE UserId = $userId";
$quizModeData = mysqli_query($con, $getQuizMode);
$challengeModeData = mysqli_query($con, $getChallengeMode);
// Build the response
$arr = array('Quiz' => $quizModeData, 'Challenge' => $challengeModeData);
// echo the json back:
echo json_encode($arr);
现在这是我的客户端 javascript:
var variableToSend = "109607962907537440488";
$.post('manageUserStats.php', {userId: variableToSend}, function(data){
console.log("Got these user stats: ", data);
});
当我看到控制台时,我看到它已记录:
Got these user stats: {"Quiz":{"current_field":null,"field_count":null,"lengths":null,"num_rows":null,"type":null},"Challenge":{"current_field":null,"field_count":null,"lengths":null,"num_rows":null,"type":null}}
但是,我想获取此处显示的数据:
我究竟做错了什么?为什么我不能只得到这两个数字?