I use: echo json_encode ($ Response); send associative array back to jQuery Ajax. Whenever I try to read each value of an ID key, I get an undefined value. Please help me figure out what I'm doing wrong. thanks in advance
My PHP code is:
$Stuff = 'Hello world'; $Success = true; $Content = $Stuff; $Response = array('Success' => $Success, 'Content' => $Content); echo json_encode($Response);
# #
My JS code is:
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);} });
source share