Sto usando: echo json_encode ($ Response); per inviare un array associativo a JQuery Ajax. Ogni volta che provo a leggere ogni valore della chiave ID, ottengo un valore indefinito. Ti prego, aiutami a capire quello che sto facendo così sbagliato ... Grazie in anticipoModo corretto per leggere 'echo json_encode()' da JQuery
My Code PHP:
$Stuff = 'Hello world';
$Success = true;
$Content = $Stuff;
$Response = array('Success' => $Success, 'Content' => $Content);
echo json_encode($Response);
# #
Il mio codice 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' con chiave value =>? – Niklas