jquery – 如何使用甜蜜警报添加Ajax调用

我的Ajax方法看起来像这样
$.post(url,{
            ajax_call:"putDonation",addresse:addresse,phone:phone,email:email,name:name,amount:amount,amountinwords:amountinwords
           }).done(function(data){

            console.log(data);

            var arr = [];

            try {
                  var str = "";
                  //convert to json string
                      arr = $.parseJSON(data); //convert to javascript array
                      $.each(arr,function(key,value){
                        str +="<li>"+value+"</li>";
                    });
                       alert(str);
                       $(".alert-danger").show();
                       $("#error").html(str);

              } catch (e) {
                  swal("Jay Gayatri !",'Donation Sucessful',"success")
                  $("#donation")[0].reset();
              }


           })

我想展示一个像这样的甜蜜警报警告弹出窗口

swal({   
                title: "Are you sure ?",text: "You will not be able to recover this imaginary file!",type: "warning",showCancelButton: true,confirmButtonColor: "#DD6B55",confirmButtonText: "Yes,delete it!",cloSEOnConfirm: false 
              },function(){   
                  swal("Deleted!","Your imaginary file has been deleted.","success"); 
                });

如果他们点击取消它不应该进行ajax呼叫,如果他们选择是,那么只有呼叫应该发生

那么任何人都可以告诉我如何在Sweet Alert方法中嵌入Ajax方法

谢谢

解决方法

一个简单的例子,我可以告诉你我是如何在我的网站上做到的.我把Ajax调用放在甜蜜警报中.
function deleteorder(orderid) {
        swal({
          title: "Are you sure?",text: "Are you sure that you want to cancel this order?",cloSEOnConfirm: false,cancel it!",confirmButtonColor: "#ec6c62"
        },function() {
            $.ajax(
                    {
                        type: "post",url: "/admin/delete_order.PHP",data: "orderid="+orderid,success: function(data){
                        }
                    }
            )
          .done(function(data) {
            swal("Canceled!","Your order was successfully canceled!","success");
            $('#orders-history').load(document.URL +  ' #orders-history');
          })
          .error(function(data) {
            swal("Oops","We Couldn't connect to the server!","error");
          });
        });
       }

因此,只有按下确认按钮才能进行ajax调用.我希望这可以帮助您按照需要的方式安排代码.

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...