Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

229
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda