console.log(data) gives the following results
{
"ERRORS": [
{
"MESSAGE": "Error on API.",
"CODE": "hermes05"
}
],
"DATA": {}
}
When I try to get the value message out I get undefined, why?
error: function(data){
console.log(data.ERRORS[0].MESSAGE);
}
FULL CODE
$.ajax({
type: "POST",
dataType: "json",
url: "http://api.domain.com/something",
data: {
// Send value in mobile input field.
mobile: $("#mobileNo").val()
},
success: function(data){
},
error: function(data){
console.log(data.ERRORS.MESSAGE);
}
});
// stop button from submitting.
event.preventDefault(); // cancel default behavior
});
What you want is
Check out the difference between
successanderrorat http://api.jquery.com/jQuery.ajax/