[英]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.