Skip to content

Instantly share code, notes, and snippets.

@adammcarth
Last active December 25, 2015 18:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save adammcarth/7022335 to your computer and use it in GitHub Desktop.
Save adammcarth/7022335 to your computer and use it in GitHub Desktop.
Working with a json response in jQuery.
$.ajax({
// blah-blah-blah,
success: outputSomething
});
function outputSomething(data) {
$.each(data.errors, function(field, message) {
alert(field); // alert("body"), alert ("name")
})
}
{
"status": 0,
"errors": {
"body": "You need to enter a comment!?",
"name": "Please enter your name."
},
"message": "Your comment failed to submit. Please correct any errors and try again."
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment