最後,我從PHP中獲得了一些輸出,而不是「數組」。這花了我一天,AAAAHHHH。從JS數組中取出數據
(參見here用於溶液)
因此,這是從XMLHTTP請求(到PHP)的返回值,通過在JS回調。我在PHP中使用print_r
。
我在這裏發佈結果摘錄。 我的新問題:
- 這是什麼數據結構?
如何從此結構中獲取元素,如CourseID(在JS中)?
[0] => Parse\ParseObject Object ( [serverData:protected] => Array ( [CourseID] => DEMO2 [EndDate] => DateTime Object ( [date] => 2017-03-31 10:26:00.000000 [timezone_type] => 2 [timezone] => Z ) [InfoTitle1] => Welcome [InfoText1] => Welcome to your course, called "sense & sales". [Admin] => [email protected] )
我的PHP代碼是
function getGroups(){
$query = new ParseQuery("CourseInfo");
$query->equalTo("Admin", "[email protected]");
$results = $query->find();
// echo $results // this lead to the string "array"
//print_r($results); // this leads to the complicated array
//echo "<script>\r\n var phpOutput = " . json_encode($results) . ";\r\n console.log(phpOutput);\r\n</script>";
// this leads to [{},{}];
}
可能是'$ data [0] - > CourseId'。 – ceejayoz
你需要序列化你的數組,在標記或AJAX調用中 –
你已經標記了這個JavaScript,這個問題應該是獨立的,沒有人需要回頭看看你的另一個。 –