我正在使用:echo json_encode($ Response);將關聯數組發送回JQuery Ajax。每當我嘗試讀取每個ID鍵值時,我都會得到一個未定義的值。請幫我找出我在做什麼錯了...在此先感謝正確的方式來閱讀從JQuery echo'json_encode()'
我的PHP代碼:
$Stuff = 'Hello world';
$Success = true;
$Content = $Stuff;
$Response = array('Success' => $Success, 'Content' => $Content);
echo json_encode($Response);
# #
我的JS代碼:
var sFirstName = $('#student_first_name').attr('value');
$.ajax({
type: "GET",
url: "../pgs/UpdateEditAStudent.php",
data: "FirstName="+ sFirstName ,
//The below code will give me: {"Success":true,"Content":"Hello world"}
success: function(data){$("#Ajax_response").html(data);}
//The popup window will show me "Undefined"
//and: {"Success":true,"Content":"Hello world"}
success: function(data){$("#Ajax_response").html(data); alert(data.Content);}
});
的Javascript'與關鍵=>值arrays'? – Niklas