Problem with file upload with ajax/jquey and Laravel 5.7

Asked

Viewed 38 times

0

Good morning friends, I need to make a request in ajax with Aravel 5.7, but for some reason ajax is only processing and does not return a response, follow the code:

Ajax:

 jQuery.ajax({
                    url: "{{ url('/gravar/audio') }}",
                    method: 'post',
                    data: {
                        audio : jQuery("#audio")[0].files[0]
                    },
                    contentType: false,
                    success: function(result){

                        // Definindo estilo da mensagem 
                        mensagem.attr('class', 'alert alert-success');
                        // Exibindo mensagem
                        mensagem.html(result);
                        botao.button('reset');
                        if(result == "ok")
                        {

                            //limpa formulario
                            $('#form1').each(function () {
                                this.reset();
                            });
                        }
                    },
                    error: function (resp) {
                        // Definindo estilo da mensagem 
                        mensagem.attr('class', 'alert alert-danger');
                        // Exibindo mensagem
                        mensagem.html('Erro de processo com servidor!');
                        botao.button('reset');
                    }

                });
            });

Controller:

public function store(Request $request)
{

if ($request->hasFile('audio') ) 
        {
            echo'arquivo valido';
        }
        else
        {
            echo'arquivo não valido';
        }
}

When no file is placed returns invalid file, when you select the file is processing and does not bring a response =(.

  • Try to add cache: false,processData: false,

  • I tried, but returns invalid file =(

  • Are multiple files?

  • one, one audio in case

  • Tries To Change From jQuery("#audio")[0] for jQuery("#audio")

  • He just keeps suing, doesn’t return anything =(

  • Check in Sponse if it shows anything?

  • Give 'space' after echo

  • Response returns nothing, so it is processing that in the case it is only in style defined before the request.

  • gives a dd($request->all() )

  • it returns like this: [] that already with Selected file

  • Not sending the aqruivo

  • I realize the problem is in jquery, but I can’t see where, maybe on date... but I’ve touched it several times and it won’t go...=(

  • You imported the jquery libraries?

  • yes, I use these: <script src="{Asset('js/jquery-3.2.1.min.js')}}"></script> <! -- jQuery 3 --> <script src="{{Asset('js/jquery/dist/jquery.min.js')}}"></script> <! -- Bootstrap 3.3.7 --> <script src="{{Asset('css/bootstrap/dist/js/bootstrap.min.js')}}"></script> <! -- Slimscroll -->

  • When I do not select a file it returns not valid file as in the method, but when I select it does not return anything, when the date parameter looks like this: audioreport : jQuery("#audiolaudo")[0]. files[0]

  • I will try to resolve with a jquery upload plug

  • and if you put dataType: 'json'

  • I’m not using json

Show 14 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.