【问题标题】:How to add Confirm Message in Ajax jQuery [duplicate]如何在 Ajax jQuery 中添加确认消息 [重复]
【发布时间】:2018-05-16 17:02:42
【问题描述】:

我需要确认箱。它应该显示消息“你想删除记录吗”。如果是,请删除。没有消息将被关闭,这是你做的简单的事情。我尝试了下面我附上的编码,请仔细阅读代码。当我运行代码时,不会显示任何输出。你能给出好的解决方案吗谢谢。

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);
            //
            }

            });
            }, }
        }
    }

【问题讨论】:

  • 你用过哪个确认
  • 要删除记录吗?这是需要显示的确认信息
  • 你能写代码吗?
  • 检查之前发送“重复”接受的答案。
  • 我检查过先生。我的编码我不知道怎么写

标签: php jquery


【解决方案1】:

我已经查看了您的 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>

【讨论】:

    【解决方案2】:

    试试这个:

    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;
        }
    
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-06-07
      • 2015-11-25
      • 2023-03-25
      • 1970-01-01
      • 1970-01-01
      • 2020-10-03
      • 2023-03-16
      相关资源
      最近更新 更多