I have a PHP script which sends me back JSON (with proper headers, confirmed by response headers in Chrome Dev Tools). When I do a POST request in jQuery, like this:
var request = $.post(formAction, formData);
I "need" to handle accessing JSON properties differently for .done()
and .fail()
(details
being a property), thus:
request.done(function(response) {
$('#response').text(response.details);
});
request.fail(function(response) {
$('#response').text(response.responseJSON.details);
});
What is the recommended way of accessing JSON properties in ubiquitous manner, so I can just call a always()
function ? For instance, when the fail() method fires, and I do console.log(response.details)
I get errors telling me that that property is not found.