When I get the status code 400 I handle the XMLHttpRequest
object in this way (1) and it work.
Anyway I suppose this code is quite specific to my use case.
I would like to be more generic like:
1) How should I handle the server error when I get the status code 500?
(1)
_.each((JSON.parse(xhr.responseText)).children, function (xhrObject, name) {
element.find('[name="' + name + '"]')
.parent().append($('<div>')
.attr('class', 'is-input-invalid')
.text(xhrObject.errors));
});