How to Add Ajax Call with sweet alert

前端 未结 4 1216
后悔当初
后悔当初 2020-12-18 00:08

My Ajax method looks like this

$.post(url,{
            ajax_call:\"putDonation\",
            addresse:addresse,
            phone:phone,
            email         


        
4条回答
  •  南笙
    南笙 (楼主)
    2020-12-18 00:25

    For a quick example i can show you how i did it on my site. I put the Ajax call inside the sweet alert.

        function deleteorder(orderid) {
            swal({
              title: "Are you sure?", 
              text: "Are you sure that you want to cancel this order?", 
              type: "warning",
              showCancelButton: true,
              closeOnConfirm: false,
              confirmButtonText: "Yes, 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");
              });
            });
           }
    

    So the ajax call only gets made if you press the confirm button. I hope this can help you to arrange your code the way you need it.

提交回复
热议问题