简体   繁体   English

未捕获的 ReferenceError:id 未在 HTMLButtonElement.onclick 中定义

[英]Uncaught ReferenceError: id is not defined at HTMLButtonElement.onclick

I'm trying to code a detailed ticket information from database that could be deleted by the admin.我正在尝试从数据库中编写可以被管理员删除的详细票证信息。 I want to use jquery ajax to remove it once the user have click on the button一旦用户单击按钮,我想使用 jquery ajax 将其删除

my codes are :我的代码是:

` `

<form class="white" method="post" action="" id="frmBA2N29F">
<span class="col3">BA2N29F</span>
<span class="col3">Medan(KNO)</span>
<span class="col3">Jakarta (CGK)</span>
<span class="col3">BA</span>
<span class="col2">BA001</span>
<span class="col4">2016-01-01</span>
<span class="col3">05:00:00</span>
<span class="col3">07:00:00</span>
<span class="col1">60</span>
<span class="col3">560000.00</span>
<span class="col3">560000.00</span>
<span class="col3">280000.00</span>
<button class = "delete" type="button" id="deleteBA2N29F" onClick = "delete_row(BA2N29F);">delete</button>
</form>

` `

my javascript function :我的 javascript 函数:

<script type="text/javascript" src="../../JS/jquery-3.1.1.min.js"></script>
    <script>
function delete_row(id)
{
 $.ajax
 ({
  type:'post',
  url:'delete-ticket.php',
  data:{
   delete_row:'delete_row',
   row_id:id,
  },
  success:function(response) {
   if(response=="success")
   {
    var row=document.getElementById("frm"+id);
    row.parentNode.removeChild(row);
   }
  }
 });
}
</script>

and my delete-ticket.php code :和我的 delete-ticket.php 代码:

<?php
include_once '../../database.php';
if(isset($_POST['delete_row']))
{
 $row_no=$_POST['row_id'];
 mysqli_query($connection,"delete from flight where flight_id='$row_no'");
 echo "success";
 exit();
}
?>

The message that I got from my browser is我从浏览器收到的消息是

tiket-list.php:98 Uncaught ReferenceError: BA2N29F is not defined
    at HTMLButtonElement.onclick

So what's the error in my code?那么我的代码中的错误是什么?

Your argument to delete_row() function should be wrapped in quotes since it is a string literal otherwise it'll be interpreted as a variable which would throw a undefined variable error since it is not defined anywhere.您对delete_row()函数的参数应该用引号括起来,因为它是一个字符串文字,否则它将被解释为一个变量,该变量会抛出未定义的变量错误,因为它没有在任何地方定义。

Change your line to this:将您的线路更改为:

<button class = "delete" type="button" id="deleteBA2N29F" onClick = "delete_row('BA2N29F');">delete</button>  

您按钮的 onclick 函数的变量必须用引号分配,因为它的值是字符串。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 未捕获的ReferenceError :(函数)未在HTMLButtonElement.onclick中定义 - Uncaught ReferenceError: (function) not defined at HTMLButtonElement.onclick 未捕获的ReferenceError:未在HTMLButtonElement.onclick中定义查找 - Uncaught ReferenceError: lookup is not defined at HTMLButtonElement.onclick 未捕获的 ReferenceError:showCurrentPage 未在 HTMLButtonElement.onclick 中定义 - Uncaught ReferenceError: showCurrentPage is not defined at HTMLButtonElement.onclick 未捕获的 ReferenceError:在 HTMLButtonElement.onclick 中未定义 postAcmgForm - Uncaught ReferenceError: postAcmgForm is not defined at HTMLButtonElement.onclick 未捕获的ReferenceError:HTMLButtonElement.onclick中未定义submitToAPI - Uncaught ReferenceError: submitToAPI is not defined at HTMLButtonElement.onclick Uncaught ReferenceError: (function) is not defined at HTMLButtonElement.onclick - Uncaught ReferenceError: (function) is not defined at HTMLButtonElement.onclick 未捕获的ReferenceError:在HTMLButtonElement.onclick中未定义函数 - Uncaught ReferenceError: function is not defined at HTMLButtonElement.onclick 未捕获的ReferenceError:未在HTMLButtonElement.onclick上定义toggleFunction - Uncaught ReferenceError: toggleFunction is not defined at HTMLButtonElement.onclick 未捕获的ReferenceError:未在HTMLButtonElement.onclick上定义测试 - Uncaught ReferenceError: testing is not defined at HTMLButtonElement.onclick 未捕获的 ReferenceError:异步未在 HTMLButtonElement.onclick 中定义 - Uncaught ReferenceError: async is not defined at HTMLButtonElement.onclick
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM