Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

227
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!