How to Add Ajax Call with sweet alert

前端 未结 4 1213
后悔当初
后悔当初 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:30

    This is my code use in my site.

                swal({
                  title: 'Are you sure?',
                  text: "Are you sure that you want to cancel this order?", 
                  showCancelButton: true,
                  confirmButtonText: 'Confirm',
                  cancelButtonText: 'Cancel',
                  showLoaderOnConfirm: true,
                  preConfirm: function () {
                    return new Promise(function (resolve, reject) {
                        $.ajax({
                             success: function(response) {
                                  resolve(response)
                             },
                             error: function(a, b, c){
                                  reject("error message")
                             }
                        })
                    })
                  },
                  allowOutsideClick: false
                }).then(function (response) {
    
                    swal({
                      title: 'Success',
                      type: 'success',
                      html: '

    Thank you

    ', showCancelButton: false, confirmButtonColor: '#3085d6', confirmButtonText: 'Close!', allowOutsideClick: false }).then(function () { window.location = '/'; }) })

    In

    preConfirm: function () { return new Promise(function (resolve, reject) {}) }
    

    You must call

    resolve(response)
    

    or

    reject()
    

    after ajax responses.

提交回复
热议问题