php - ajax删除不适用于onclick事件
问题描述
我需要一些帮助,请我一直在搜索并试图知道为什么当我单击该按钮时什么都没有发生
html:
<td></td>
<td></td>
<td></td>
<td><button id="<?php echo($row['ID']); ?>" onClick="delord()" class="del" style="font-size: 12">delete</button></td>
jQuery:
function delord(){
var x = event.target.id;
$.ajax({
url: 'delorder.php?id=' + x,
success: function(){
alert('deleted');
}
});
}
我尝试alert(x);
在我的 jquery 代码中输入并返回值然后我尝试转到“delorder.php?id=335”并且该行已成功删除
只是当我用 ajax 尝试它时它不起作用
解决方案
做这些
<table>
<thead>
<tr>
<td>Name</td>
<td></td>
</tr>
</thead>
<tbody>
<tr>
<td>Stephen</td>
<td><button onclick="deleteRow('delete',<?php echo($row['ID']); ?>)">Delete</button></td>
</tr>
</tbody>
</table>
jQuery:
function deleteRow(action,id){
$.ajax({
url: 'delorder.php?id=' + id,
success: function(){
alert('deleted');
}
});
}
推荐阅读
- javascript - 如何使用 window.postmessage 与父窗口通信
- flutter - Dart中Function类型参数的默认值
- perl - Parallel::ForkManager 给出 - 子进程 STDIN 不是真正的系统错误
- docker - 从 DockerHub 拉取时,.NetCore Api Docker Image 不工作
- javascript - 使用 Enzyme mount() 访问嵌套组件
- python - Flask URL 重定向,其中参数是 URL 的一部分
- python - 我正在尝试使用正则表达式获取以 < 开头并以 > 结尾的子字符串并删除它们以创建一个新字符串
- node.js - How do you update a thumbnailPhoto in Active Directory using NodeJS and ldapjs?
- database - Unable to install Sample OE schema in Pluggable DB in Oracle 19c
- java - 实现接口并使用类对象而不是接口对象