當我選擇一個購買了產品的帳戶時,我會彈出一個選項來顯示它是哪個產品,但是如果我們選擇一個購買了其他產品的帳戶,這個選項會第二次出現。
我的腳本代碼
$("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();
}
}
})
})
圖片
我的訂單-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>
uj5u.com熱心網友回復:
.after(data)不斷在表單末尾添加更多內容。
相反,創建一個特定的 div 或您想要放置此內容的東西,并使用.html(data)它來寫入它。然后,這將在您每次運行時覆寫內容,而不是將其附加到之前添加的內容中。
參考:
- https://api.jquery.com/after/
- https://api.jquery.com/html/
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/483396.html
標籤:javascript php html jQuery 阿贾克斯
上一篇:我怎樣才能把逗號放在千位?
下一篇:使用cypress測驗網路請求
