0
Colleagues,
I have an excerpt of the code where when clicking the button Add fields, I can add and send to the database.
In the visualization, I’m bringing the data in the following way:
<?php
$sql = mysqli_query($this->conexao,"SELECT * FROM produtos WHERE IDProdutos = '".$idProdutos."';");
$visualizar = "<table border=\"0\">";
while($jmTamanhos = mysqli_fetch_object($sql)){
if($jmTamanhos->Tamanho != ""){
$visualizar .= "<tr class='linhas'>
<td style=\"padding: 5px\"><input type=\"text\" name=\"Tamanho[]\" class=\"form-control\" placeholder=\"Tamanho\" value='".$jmTamanhos->Tamanho."'></td>
<td style=\"padding: 5px\"><input type=\"text\" name=\"Estoque[]\" class=\"form-control pull-left\" placeholder=\"Estoque\" value='".$jmTamanhos->Estoque."'></td>
<td style=\"padding: 5px\"><button type=\"button\" class=\"removerCampo btn btn-danger\" title=\"Remover linha\"><i class=\"fa fa-minus-square\" aria-hidden=\"true\"></i> Remover</button></td>
</tr>";
}
}
$visualizar .= "</table>";
return $visualizar;
}
?>
So far so good. He returns to me:
So far all right, but how would I do for that by clicking remove, direct to the deletion page? I tried with the code below, but I’m not getting it. Follow the code:
<script type="text/javascript">
$(function () {
function removeCampo() {
$(".removerCampo").unbind("click");
$(".removerCampo").bind("click", function () {
if($("tr.linhas").length > 1){
$(this).parent().parent().remove();
}
});
}
$(".adicionarCampo").click(function () {
novoCampo = $("tr.linhas:first").clone();
novoCampo.find("input").val("");
novoCampo.insertAfter("tr.linhas:last");
removeCampo();
});
$(".removerCampo").click(function () {
$.post("excluir-tamanhos.php", $("#excluirCampos").serialize(), function(response) {
alert('aqui 2');
$('#success').html(response);
removeCampo();
});
return false;
});
});
</script>
what exactly isn’t working? the file
excluir-tamanhos.php
is receiving the data? Put it there... (The -1 was not I)– LocalHost
I changed it to $.post("delete-sizes.php", {Idproducts: 15, Size: 34}, Function(Response) { e worked. How do I pass product value 15 and size 34? when I put id='size' in name='Size[]' to work.
– user24136
Hello @Localhost .. I can’t actually upload the data to the file delete-sizes.php. The problem is not in PHP but because I cannot send the data to that page.
– user24136
I think I get it, and I think your mistake might be in the way that you’re sending the data, with the serialize. You can create the same function to remove the data and still remove from the database. Ai Voce can take the data that Voce will delete and send, instead of giving the serialize
– LocalHost
Unfortunately I am a layman in jquery. You would have some example to show me?
– user24136
I’ll see if I can set an example here
– LocalHost