我正在尝试编写可以由管理员删除的数据库中的详细故障单信息。一旦用户点击按钮
,我想使用jquery ajax删除它我的代码是:
`
<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>
`
我的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>
和我的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();
}
?>
我从浏览器收到的消息是
tiket-list.php:98 Uncaught ReferenceError: BA2N29F is not defined
at HTMLButtonElement.onclick
那么代码中的错误是什么?
答案 0 :(得分:0)
你对delete_row()
函数的参数应该用引号括起来,因为它是一个字符串文字,否则它将被解释为一个变量,它会抛出一个未定义的变量错误,因为它没有在任何地方定义。
将您的行更改为:
<button class = "delete" type="button" id="deleteBA2N29F" onClick = "delete_row('BA2N29F');">delete</button>
答案 1 :(得分:0)
您的按钮的onclick函数变量必须使用引号分配,因为它的值是String。