When I use Ajax to return a result from the database, it stores that result by making a sort of queue on the next requests, returning other queries old data with the current ones, eg ...
$inputgetCod = (isset($_POST['codBarras'])) ? $_POST['codBarras'] : '';
...
else{
$sql = 'SELECT nome,valorUnt from produtos where codigoBarras = ?';
$stm = $conexao->prepare($sql);
$stm->bindValue(1, $inputgetCod);
$stm->execute();
$dads = $stm->fetch(PDO::FETCH_OBJ);
$vlt = $dads->valorUnt;
$nm = $dads->nome;
$retorno = array('codigo' => 0, 'mensagem' => 'cadastrado com sucesso', 'acerto' => $acerto, 'nome' => $nm, 'vlt' => $vlt);
echo json_encode($retorno);
exit();
}
Ajax
var ajaxID = 0;
$.ajax({
type : 'POST',
url : '../phpVld/validaGetprod.php',
data : data,
dataType: 'json',
cache : false,
success : function(response){
$(".algumCampo").append(response.algum_dado);
}
When I call this request again through a button it returns the old data next to the current one, is there any way to return only one request data at a time?