I'm making a POST request using $.ajax({}) with Jquery. I purposely send missing fields to get server-side validation messages. The errors are these receiving in the following way in the object jqXHR.
error: function(jqXHR,textStatus,errorThrown){
console.log(jqXHR.responseText);
console.log(jqXHR.responseJSON);
}
The errors are shown as follows:
jqXHR.responseText
{"message":"The given data was invalid.","errors":{"recibo_de":["Recibo de: Requerido"],"id_proveedor":["Proveedor: Requerido"],"fecha_inicio":["Fecha inicial: Requerido"],"fecha_fin":["Fecha final: Requerido"]}}
jqXHR.responseJSON
{message: "The given data was invalid.", errors: {…}}
errors:
fecha_fin : ["Fecha final: Requerido"]
fecha_inicio : ["Fecha inicial: Requerido"]
id_proveedor : ["Proveedor: Requerido"]
recibo_de : ["Recibo de: Requerido"]
message : "The given data was invalid."
With jqXHR.responseJSON.message I get the message "The given data was invalid.", Now, how can I get the fields one by one "recibo_de","id_proveedor","fecha_inicio","fecha_fin" along with your error messages?