jquery/ajax不更新varchar id的记录

6za6bjd0  于 2021-06-18  发布在  Mysql
关注(0)|答案(2)|浏览(293)

当idIQuiryItems为数字(1)时,此函数正常工作,但当idIQuiryItems包含字母(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();
        }
    });
}

}
idIQuiryItems触发器未捕获引用错误:在htmlanchoreElement.onclick(inquiry.php?idIQuiry=1:156)中未定义a3hcu45vn
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();
?>
mklgxw1f

mklgxw1f1#

将id传递给用引号括起来的函数解决了这个问题!

deleteRecord('a3hcu45vn')
ru9i0ody

ru9i0ody2#

尝试
processdata:false,数据:“idIQuiryItems=”+idIQuiryItems,
或者
数据:{idIQuiryItems:idIQuiryItems}

相关问题