Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

232
Visualizações
I am sending a data with ajax. How can I reset the data sending process?

When I select an account that has purchased a product, I bring up an option showing which product it is, but if we select an account that has purchased another product, this option comes for the second time.

my script code

$("select.account").on('change', function() {

    var accId = $(this).children("option:selected").val();
    
    console.log(accId);

    $.ajax({

        type: 'POST',
        url: 'netting/order-ajax.php',
        data: {
            'accId': accId
        },
        success: function(data) {
            
            if (data != "FALSE") {
                $('#accform').after(data);
                
            } else {
                $('#productform').hide();
            } 
        }
    })
})

image

my order-ajax.php

if (isset($_POST['accId'])) {

$sql = $db->qSql("SELECT * FROM sales INNER JOIN account ON sales.accId = account.accId INNER JOIN product ON sales.productId = product.productId WHERE sales.accId = '{$_POST['accId']}'");

if ($sql->rowCount() > 0) { ?>

    <div id="productform" class="form-group">
        <label for="recipient-name" class="col-form-label">Ürün & Hizmet</label>
        <select class="form-control account" required name="accId">
            <option value="">Ürün & Hizmet seçiniz...</option>
            <?php
            $sql = $db->read("product", [
                "columnsName" => "productId",
                "columnsSort" => "DESC"
            ]);
            while ($row = $sql->fetch(PDO::FETCH_ASSOC)) {   ?>
                <option value="<?= $row['productId'] ?>"><?= $row['productTitle'] ?></option>
            <?php } ?>
        </select>
    </div>
about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

.after(data) keeps adding more content at the end of your form.

Instead, create a specific div or something into which you want to place this content, and use .html(data) to write into it. This will then overwrite the content each time you run it, instead of appending it to what was added previously.

References:

  • https://api.jquery.com/after/
  • https://api.jquery.com/html/
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda