Loop through json object and print results
I have the follow开发者_如何转开发ing json, and I want to loop through it and print out the error messages using jQuery.
Any help would be great. thanks!
var validationErrors = {"errors":["Please enter the month (1-12)","Please enter a day 1-31"]}
Edit, I know I have to use a loop, I'm just not sure really how to separate the error messages so I can print them out separately.
$('#error-container').append(
'<p class="error">'
+ validationErrors.errors.join('</p><p class="error">')
+ '</p>'
);
$(validationErrors.errors).each(function() {
$('#output').append($('<p>').text(this.toString())); //#output is where you want it printed
});
精彩评论