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,
– adventistaam
I tried, but returns invalid file =(
– Michel Diniz
Are multiple files?
– adventistaam
one, one audio in case
– Michel Diniz
Tries To Change From
jQuery("#audio")[0]
forjQuery("#audio")
– adventistaam
He just keeps suing, doesn’t return anything =(
– Michel Diniz
Check in Sponse if it shows anything?
– adventistaam
Give 'space' after echo
– adventistaam
Response returns nothing, so it is processing that in the case it is only in style defined before the request.
– Michel Diniz
gives a
dd($request->all() )
– adventistaam
it returns like this: [] that already with Selected file
– Michel Diniz
Not sending the aqruivo
– adventistaam
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...=(
– Michel Diniz
You imported the jquery libraries?
– adventistaam
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 -->
– Michel Diniz
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]
– Michel Diniz
I will try to resolve with a jquery upload plug
– Michel Diniz
and if you put dataType: 'json'
– adventistaam
I’m not using json
– Michel Diniz