Here is another JSON question (I always struggle with arrays).
My PHP code returns the following JSON structure:
[{"breed":{"msg":"Breed is required","placement":"#breed_error_1","return":"false"}},{"breed":{"msg":"Breed does not exist","placement":"#breed_error_2","return":"true"}}]
My PHP code is:
$breed[]["breed"] = array("msg"=>"Breed is required","placement"=>"#breed_error_1", "return"=>"false");
$breed[]["breed"] = array("msg"=>"Breed does not exist","placement"=>"#breed_error_2", "return"=>"true");
And the AJAX code:
$.ajax({
type: 'POST',
cache: false,
url: "validate_breed",
data: element+"="+$(elementSelector).val()+"&v="+validateElement,
context: document.body,
dataType: 'html',
success: function(data){
alert(data);
}
});
alert(data)
alerts out the JSON structure for debugging purposes.
How do I access the breed section of JSON object and all of the following index/keys?