0
Hello guys my first post here, I’m having a problem sending more than one attachment via Ajax. I have an API in jersey that gets the call. if I send only one attachment works well, however if I select more than one attachment, only one.
My function that passes
function gravar() {
var campo = document.getElementById('id').value;
$('#mensagem_success').hide();
$('#mensagem_danger').hide();
var conteudo = JSON.stringify($('#frmProposta').serializeObject());
$.ajax({
url : "https://url",
type : "POST",
contentType : "application/json; charset=utf-8",
dataType : "json",
data : conteudo,
success : function(result) {
$('#mensagem_success').html(' Gravado com Sucesso');
$('#mensagem_success').show();
},
error : function() {
$('#mensagem_danger').html('Erro ao gravar ');
$('#mensagem_danger').show();
}
});
// Get form
var form = $('#frmProposta')[0];
var files = $('#uploadFile')[0].files;
for (var i = 0; i < files.length; i++){
var nome = files[i].name
// Create an FormData object
var data = new FormData(form);
$
.ajax({
type : "POST",
enctype : 'multipart/form-data',
url : "https://url",
data : data,
processData : false,
contentType : false,
cache : false,
timeout : 600000,
success : function(data) {
},
error : function() {
}
});
}
};
My form
<form class="form-group" name="frmProposta" id="frmProposta">
<div class="box-body">
<!-- <div class="form-group col-md-6">
<label for="cod_user">Código do usuário *</label>
</div> -->
<input type="hidden" class="form-control" id="id" name="id" >
<div class="box-body">
<div class="form-group col-md-6">
<label for="email_usuario">Tematica</label>
<select class="form-control"name="tema" id="tema">
<option>Tematica</option>
<option>Inovação</option>
<option>Emprego</option>
<option>Segurança</option>
<option>Infraestrutura</option>
<option>Mobilidade</option>
<option>Economia</option>
<option>Educação</option>
<option>Lazer</option>
<option>Saúde</option>
<option>Tecnologia</option>
<option>Outros</option>
</select>
</div>
<div class="form-group col-md-6">
<label for="nome_login">Resumo*</label> <input type="text"
class="form-control" id="resumo" name="resumo"
placeholder="Resumo" maxlength="400">
</div>
<div class="form-group col-md-6">
<label for="senha">Descrição*</label> <textarea cols="10" rows="5"
class="form-control" id="descricao" name="descricao"
placeholder="Descrição" maxlength="400"></textarea>
</div>
<div class="form-group col-md-6">
<label for="nome_login">Situação Atual*</label> <textarea cols="10" rows="5"
class="form-control" id="situacao" name="situacao"
placeholder="Situação Atual" maxlength="400"></textarea>
</div>
<div class="form-group col-md-6">
<label for="senha">Indicadores*</label> <textarea cols="10" rows="5"
class="form-control" id="indicadores" name="indicadores"
placeholder="indicadores" maxlength="400"> </textarea>
</div>
<div class="form-group col-md-6">
<label for="senha">Observações*</label> <textarea cols="10" rows="5"
class="form-control" id="obs" name="obs"
placeholder="Observações" maxlength="400"> </textarea>
</div>
<div class="form-group col-md-6">
<label for="nome_login">Arquivo</label><input type=file "multiple"
id="uploadFile" name="uploadFile" size="100" />
</div>
<!-- /.box-body -->
<div class="box-footer col-md-12">
<button type="button" class="btn btn-primary"
onclick="gravar()">Salvar</button>
<button type="reset" class="btn">Limpar</button>
</div>
</div>
</form>
What is the relation with java?
– user28595
API you receive is in java
– Thiago Juliano
But there’s nothing java in the question.
– user28595
Articuno, I apologize for my tag formation. already adjusted
– Thiago Juliano
You’re not going through the same as one
array
,name="uploadFile[]"
– Rafael Augusto