3
I have the following Form:
<div class="row" id="importar">
<form id="convidados">
<input type="hidden" value="<?php echo $this->uri->segment(4); ?>" id="id_cliente" name="id_cliente">
<div id="multiple_upload">
<input type="file" id="uploadChange" onchange="checkfile(this);" />
<div id="message">Selecione o Arquivo</div>
<input type="button" id="botao_" class="btn btn-primary" value="Importar" disabled />
<div id="lista">
</div>
</div>
</form>
<div>
And the jQuery:
// importar
$(function () {
var form;
$('#uploadChange').change(function (event) {
form = new FormData();
form.append('uploadChange', event.target.files[0]); // para apenas 1 arquivo
//var name = event.target.files[0].content.name; // para capturar o nome do arquivo com sua extenção
});
$('#botao_').click(function () {
var id_cliente = $("#id_cliente").val();
$.ajax({
url: basePath + 'ajax/importar_lista',
data: {upload: form, id_cliente: id_cliente},
processData: false,
contentType: false,
type: 'POST',
success: function (data) {
console.log("success");
$('#importar').html("<div style='padding: 100px;'><center><img src='../../../assets/img/importando-lista.gif'></center></div>");
setTimeout(function(){
$('#importar').html(data);
},3000);
}
});
});
});
I need to add the following variable to pass in ajax/import_list:
var id_cliente = $("#id_cliente").val();
How can I pass the id_cliente
inside ajax? If I pass on as @Kayobruno’s response, I need to go over with var?
It’s supposed to work. It’s not carrying anything ? You checked if the Hidden field is worth anything ?
– Diego Souza
The Hidden field has value, and is carrying nothing.. If I put date: form, it takes only the upload data.. is it because of the function above jquery?
– Sr. André Baill
Before you call Ajax, do it
console.log($('form').serialize());
and see what returns.– Diego Souza
Returned only id_client=3
– Sr. André Baill
Same thing... I can’t receive the data from the id_client, and that way, neither the upload data, can it be because of the form? i put so <form id="guests">...
– Sr. André Baill
Good observation, I had not come across. It has mandatory parameters, as the
enctype
.– Diego Souza
I’m out of luck today, gave the same thing rssrsrsrsr...
– Sr. André Baill
In PHP do
print '<pre>'; print_r($_POST) print '</pre>';
– Diego Souza
I’ve done, POST, GET, REQUEST AND FILES all return array()
– Sr. André Baill
Just leave it at AJAX:
data: $('form').serialize(),
– Diego Souza
In an attempt, I did as follows @Gumball: inside the ajax... data: {id_client: id_client}, ai with print_r($_REQUEST) or POST, appears. Beyond the date: form, I added the data:..
– Sr. André Baill
Let’s go continue this discussion in chat.
– Sr. André Baill