while($row = $result->fetch_array()) {
array_push($json_result,
array('crewID'=>$row[0],
'FName'=>$row[1],
'LName'=>$row[2],
'smBook'=>$row[3],
'contactNo'=>$row[4],
'email'=>$row[5],
'address'=>$row[6],
'birthday'=>$row[7],
'emergencyCN'=>$row[8],
'emergencyPerson'=>$row[9],
'loyaltyCN'=>$row[10]));
}
echo json_encode(array($json_result),JSON_PRETTY_PRINT);
JSON回聲這是我的jQuery代碼:
function displayGuestData(guestID) {
$.ajax({
url:"functions/f_get_guests_json.php",
method:"POST",
data:{guestID:guestID},
dataType: "json",
success:function(response) {
alert(response.FName);
}
});
}
現在我的問題是,我得到一個未定義的錯誤,當我提醒任何JSON數據像FName
。可能是什麼問題呢?我是jQuery中的新JSON。我甚至有這樣的代碼在我的PHP:
header("Content-Type: application/json", true);
編輯:
這是JSON:
[
{
"crewID": "4",
"FName": "Abc Abc",
"LName": "Abc",
"smBook": "ABC123",
"contactNo": "12312312",
"email": "[email protected]",
"address": "56 Sasdasd Asds",
"birthday": "1995-06-11",
"emergencyCN": "12312312",
"emergencyPerson": "asdasdasd",
"loyaltyCN": "ABC123"
}
]
你能否也請添加至少一個你的PHP腳本的輸出片段? – Shadow
這是您的陣列結構:'陣列 ( [0] =>數組 ( [0] =>數組 ( [crewID] => [FName參數] => [LName的] => [smBook ] => [contactNo] => [電子郵件] => [地址] => [生日] => [emergencyCN] => [emergencyPerson] => [loyaltyCN] => ) ) ) ' 使用'response [0] [0] .FName'獲取數組項 – diavolic
添加console.log(response);成功的ajax功能將幫助您瞭解從服務器端返回的值。 – Lalit