I've been struggling to display my JSON response from PHP in the browser console using JavaScript. Despite researching on various websites, I still can't seem to figure it out.
Here's a sample of the JSON data:
{"0":{"codigo_intervencao":"Apoio Emocional - 5270"},"1":{"tempo":"30"},"2":{"codigo_intervencao":"Apoio Emocional - 5270"},"3":{"tempo":"30"},"4":{"codigo_intervencao":"Apoio Emocional - 5270"},"5":{"tempo":"231518"},"6":{"codigo_intervencao":"Apoio Emocional - 5270"}}
My goal is to print each value of the key "codigo_intervencao" in the console, but I haven't been successful so far.
I attempted something like this:
$(document).ready(function() {
$( "#target" ).click(function() {
console.log("Select JS");
$.ajax({
type: "POST",
url: "select.php",
dataType: 'html',
success: function(response) {
console.log("Response:" + response); // This prints the JSON data above
var array = $.parseJSON(response);
var tempo = 0;
var arrayLength = array.length;
for (var i = 0; i < arrayLength; i++) {
console.log(array[i]['codigo_intervencao']);
}
});
});
});