Nix Nix - 1 year ago 229
Ajax Question

Form validation with ajax and laravel 5.2

I'm using ajax to submit my form. The issue I'm having is that if I have 2 or more errors that need to be displayed, I can't seem to get them to be displayed separately. The errors show up on 1 line.

This is my ajax code.

url: 'ceromony_post',
type: "post",
data: {'name':$('input[name=name]').val(),
'_token': $('input[name=_token]').val()
$(".success_wrapper").append('<div class="success">'+data.message+'</div>');
error: function(xhr) {
var errors = xhr.responseJSON;
var test = [[0], errors.surname[0]];

$(".error_wrapper ul").html('<li class="error">'+test.join('\n')+'</li>');

Answer Source

Use a brake

 $(".error_wrapper ul").html('<li class="error">'+test.join('</br>')+'</li>');