Ajax returning repeated data

0

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?

    
asked by anonymous 30.10.2016 / 21:59

1 answer

0

Switch

$(".algumCampo").append(response.algum_dado);

by:

$(".algumCampo").text(response.algum_dado);

append() will add more data to the element, while text() will replace with new content

    
31.10.2016 / 00:07