jeudi 28 septembre 2017

how to show error with laravel and ajax in views

I have a trouble when show error in laravel. I am using ajax to send request form from client to server and backward. This is my ajax code and seem to be function append() is not working.

$('#petition-form').on('submit', function(e) {
  e.preventDefault();
  var formdata = new FormData($(this)[0]);
  formdata.append('content', tinymce.get('content').getContent());
  $.ajax({
    url: $(this).attr('action'),
    data: formdata,
    processData: false,
    contentType: false,
    cache: false,
    method: 'POST'  
  }).done(function(response) {
   window.location.href = response.slug;
 }).fail(function(response) {
   $(this).append(response);
});
});

and here is my view

@if (count($errors) > 0)
<div class="alert alert-danger">
    <ul>
        @foreach ($errors->all() as $error)
        <li>
            
        </li>
        @endforeach
    </ul>
</div>
@endif

so anybody help me solve that! thank you



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire