I am trying to parse some very basic JSON, but I don’t know where I’m going wrong when trying to display it to the screen.
Am I not GRABBING the data correctly, such as, “data.re1Code”?
I hope someone can shed some light onto my basic question sorry.
JSON Data
[
{
"rep1FullName": "Justin Giesbrecht",
"rep1Code": "dc",
}
]
Javascript
$.ajax({
type: "GET",
url: "testJSONData.php",
dataType: "json",
success: function(data) {
$("#output").append(data.rep1FullName);
},
error: function () { alert("Error"); }
}); // End of generated json
The brackets [] make data a JSON array with your object as the 0th element so to get “Justin Giesbrecht” use the code:
$("#output").append(data[0].rep1FullName);or remove the brackets and make the JSON: