如何在 Ajax jQuery 中添加确认消息



我需要"confimation"框。 它应该显示消息"是否要删除记录"。如果是,则删除 .没有消息将被关闭 这是简单的事情,你必须这样做。 我尝试了什么 我附在下面的编码 请浏览代码。 当我运行代码时,不会显示任何输出。 你能给出一个好的解决方案吗,谢谢。

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>

试试这个:

function RemoveTeam(id) {
var r =  confirm("do you want to delete the record");
if (r == true) {


$.ajax({
type: 'POST',
url: 'remove.php',
dataType: 'JSON',
data: {id: id},
success: function (data) {

get_all();
},
error: function (xhr, status, error) {
alert(xhr.responseText);
//
}
});
} else {
return false;
}
}

最新更新