2
I have a Controller that is returning errors this way:
return response()->json(['erros' => $this->renderHttpException($e)]);
I am receiving this json as a response to the ajax request:
{"email":["The email field is required."],"telefone":["The telefone field is required."]}
I need to list these errors in a div, without having to specify each field as I did with the email, as I do?
function Create(id, url) {
$.ajax({
url: url,
data: $('#' + id).serialize(),
dataType: 'json',
type: 'POST',
error: function (data) {
var errors = data.responseJSON;
document.getElementById('message').innerHTML = errors.email;
}
});
}
Place the ajax call.
– rray
I put the call ajax @rray
– Raylan Soares
When Windows sends the error msg always from Undefined? tried to change the
error:
fordone:
and in that change check if the object has any message?– rray
It’s just
data.email
anddata.telefone
– Diego Souza
I was able to pick up with this: var errors = data.responseJSON; and putting errors.email for example. But now how do I make him run json without I have to specify the field? Because there are many, I put 2 here to simplify
– Raylan Soares
I edited the question for the current situation
– Raylan Soares