1
I’m trying to make a system where, the user selects the products and adds in a list, without the page being reloaded again. At first I made sure the page was not reloaded again using ajax
, but I have two problems, the first is that the fields of data on the customer are erased without what I wanted, the data that should be erased would be only those of the product, and the second is that I can’t think of a way to insert the data in a list and showlos posteriormente in a separate table, name, price and the total.
Ajax
$("#adicionar").click(function()
{
$.ajax({
type: 'POST',
url: '../Model/resultado.php',
success: function(data)
{
$(".table").append(data);
}
});
});
Order form
<div class="col-xs-12">
<!-- Nome -->
<div class="col-xs-3">
<!-- Legenda -->
<label for="nomeProduto" class="label label-primary">Nome do Produto</label>
<!-- Campo -->
<select class="form-control text-center" name="produto" id="nomeProduto" tabindex="2" title="Nome do Produto" onfocus="completarCamposProdutos();">
<option value=""></option>
<?php
foreach ($produtos as $produto)
{
?>
<!-- Opcoes -->
<option
value="<?= $produto['id'] ?>"
data-preco="<?= $produto["valorVenda"] ?>"
data-estoque="<?= $produto['quantidadeAtual'] ?>">
<?= $produto['nomeProduto'] ?>
</option>
<?php
}
?>
</select>
</div>
<!-- Valor Unitario -->
<div class="col-xs-2">
<!-- Legenda -->
<label for="valorUnitario" class="label label-primary">Valor Unitário</label>
<!-- Campo -->
<input type="text" name="valorUnitario" id="valorUnitario" class="form-control text-center" readonly="" title="Valor Unitario" placeholder="Valor Unitario">
</div>
<!-- Quantidade -->
<div class="col-xs-2">
<!-- Legenda -->
<label for="quantidade" class="label label-primary">Quantidade</label>
<!-- Campo -->
<input type="text" name="quantidade" id="quantidade" class="form-control text-center" placeholder="Quantidade" title="Quantidade" tabindex="3">
</div>
<!-- Total -->
<div class="col-xs-2">
<!-- Legenda -->
<label for="total" class="label label-primary">Total</label>
<!-- Campo -->
<input type="text" name="totalUnitario" id="total" class="form-control text-center" title="Total" placeholder="Total" readonly="">
</div>
<!-- Restante estoque -->
<div class="col-xs-2">
<!-- Legenda -->
<label for="estoque" class="label label-primary">Estoque restante</label>
<!-- Campo -->
<input type="text" name="estoque" id="estoque" class="form-control text-center" title="Estoque Restante" placeholder="Estoque Restante" readonly="">
</div>
<!-- Cadastrar -->
<div class="col-xs-1">
<a href="" class="btn btn-success form-control" id="adicionar" tabindex="4">OK</a>
</div>
<!-- Carregando ajax -->
<script language="javascript" src="../Util/JavaScript/AdicionarProdutosEmPedidos.js"></script>
</div>
Result.php
<?php
// Requerindo arquivos
require_once "../Util/Seguranca/ControleAcesso.php";
// Funcao que protege a logica contra acesso nao autorizado
ProtegePagina();
// Recebendo parametros por post
$nomeProduto = $_POST['produto'];
$valorUnitario = $_POST['valorUnitario'];
$quantidade = $_POST['quantidade'];
$total = $_POST['totalUnitario'];
Usually in such systems the staff makes use of
$_SESSION
– MarceloBoni
but this would not lead to page reloading?
– Rodrigo Prado
Not necessarily, you can send the data and enter
$_SESSION
usingajax
– MarceloBoni
Session seems to me to make sense, but as the user adds products to the list, as I would create Sessions for this, it would have to be something kind of automated and that can be saved in a database later
– Rodrigo Prado
It would not be creating Sesssions, in plural, you would work with the data created in a single Sesssion
– MarceloBoni
I never used Séssion that way, to half lost, can give an example?
– Rodrigo Prado
Put Session on the form page and Session on the php page that is called by ajax. And also create a remove button from the list that you remove from the page with javascript and with ajax tb you remove from the list that is in a session variable.
– Antonio Alexandre
I must be doing something wrong, because it didn’t work, I put a Session storing the product name and another in the table that should show the name of the same, when I ran ajax, nothing appears
– Rodrigo Prado