php - 如何在 Ajax jQuery 中添加确认消息
问题描述
我需要确认盒。它应该显示消息“你想删除记录吗”。如果是,请删除。没有消息将被关闭,这是你做的简单的事情。我尝试了下面我附上的编码,请仔细阅读代码。当我运行代码时,不会显示任何输出。你能给它一个好的解决方案吗谢谢。
function RemoveTeam(id) {
$.confirm({
buttons: {
hey: function () {
$.ajax({
type: 'POST',
url: 'remove.php',
dataType: 'JSON',
data: {id: id},
success: function (data) {
get_all();
},
error: function (xhr, status, error) {
alert(xhr.responseText);
//
}
});
}, }
}
}
解决方案
当我查看了您的 jquery 代码时,它可能会使用 jquery-confirm 插件,并且代码可能有助于解决您的问题。我使用虚拟 JSON 调用来生成 ajax 请求。
function removeTeam(id) {
$.confirm({
buttons: {
hey: function() {
$.ajax({
url: 'https://craftpip.github.io/jquery-confirm/bower.json',
dataType: 'json',
method: 'get'
}).done(function(response) {
console.log(response);
}).fail(function(err) {
console.log('Something went wrong.');
});
},
cancel: function() {
console.log('the user clicked cancel');
}
}
});
}
removeTeam(10);
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.js"></script>
推荐阅读
- sql - 如何适应不经常运行但资源密集型的 Azure SQL 查询
- excel - EXCEL-求和,通过索引显示数据
- java - 请求 Wifi 呼叫上的套接字工厂不起作用
- spring-aop - 使用 spring aop 获取当前用户
- javascript - 如何在 DataTables Ajax 重新加载后保留 HTML 表格样式和 on:click 属性?
- javascript - 带有表格的嵌套材质 UI 对话框未呈现
- iis - IIS 工作进程是否在高 CPU 或 RAM 上崩溃?
- c# - 如何使控件跟随其数据源?
- ios - Swift 4 insertTimeRange 添加视频轨道,但播放时不显示除了第一个
- go - 如何使用golang快速获取邮递员的表单数据?