当idInquiryItems为数字(1)时,此功能可以正常工作,但如果idInquiryItems包含字母(a3hcu45vn),则此功能将不起作用。当ID包含字母时,它甚至不会触发确认弹出窗口。

function deleteRecord(idInquiryItems) {
if(confirm("Are you sure you want to delete this line item?")) {
    $.ajax({
        url: "php/delete.php",
        type: "POST",
        data: "idInquiryItems=" + idInquiryItems,
        success: function(data){
          $("#table-row-"+idInquiryItems).remove();
        }
    });
}


}

idInquiryItems触发未捕获的ReferenceError:未定义a3hcu45vn
    在HTMLAnchorElement.onclick(inquiry.php?idInquiry = 1:156)

的HTML

<table id="inquiry-item-grid" class="w3-table w3-bordered w3-border w3-white">
    <col width="50">
    <col width="50">
    <col width="50">

    <thead>
      <tr>
        <th>Line</th>
        <th>Qty</th>
        <th>UOM</th>
        <th>Description</th>
        <th></th>
      </tr>
    </thead>
    <tbody id="table-body">

              <tr class="table-row" id="table-row-a3hcu45vn">
        <td contenteditable="true" id="Line" onBlur="saveToDatabase(this,'Line','a3hcu45vn')" onClick="editRow(this);">1</td>
        <td contenteditable="true" id="Quantity" onBlur="saveToDatabase(this,'Quantity','a3hcu45vn')" onClick="editRow(this);">1</td>
        <td contenteditable="true" id="UOM" onBlur="saveToDatabase(this,'UOM','a3hcu45vn')" onClick="editRow(this);">ea</td>
        <td contenteditable="true" id="Description" onBlur="saveToDatabase(this,'Description','a3hcu45vn')" onClick="editRow(this);">test</td>
        <td><a class="ajax-action-links w3-right" style="padding-right: 16px; cursor: pointer;" onclick="deleteRecord(a3hcu45vn);" title="Delete a3hcu45vn">X</a></td>
      </tr>
              <tr class="table-row" id="table-row-1">
        <td contenteditable="true" id="Line" onBlur="saveToDatabase(this,'Line','1')" onClick="editRow(this);">5</td>
        <td contenteditable="true" id="Quantity" onBlur="saveToDatabase(this,'Quantity','1')" onClick="editRow(this);">1</td>
        <td contenteditable="true" id="UOM" onBlur="saveToDatabase(this,'UOM','1')" onClick="editRow(this);">ea</td>
        <td contenteditable="true" id="Description" onBlur="saveToDatabase(this,'Description','1')" onClick="editRow(this);">readreadread</td>
        <td><a class="ajax-action-links w3-right" style="padding-right: 16px; cursor: pointer;" onclick="deleteRecord(1);" title="Delete 1">X</a></td>
      </tr>

    </tbody>
  </table>


的PHP

    <?php
require_once("config.php");
$pdo_statement=$pdo_conn->prepare("UPDATE InquiryItems SET Deleted = 1 WHERE idInquiryItems = '" . $_POST['idInquiryItems'] . "'");
$pdo_statement->execute();
?>

最佳答案

尝试

processData:否,
数据:“ idInquiryItems =“ + idInquiryItems,

要么

数据:{
idInquiryItems:idInquiryItems
}

关于php - jQuery/AJAX不更新带有Varchar ID的记录,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/53685041/

10-09 19:33