sweetalert 2.0 ajax,处理SweetAlert2中的AJAX返回值

我使用带有AJAX请求的SweetAlert2 Popup。一旦用户点击提交,我执行请求。 在PHP文件中,我对提交的数据进行了一些验证,根据结果,我想在SweetAlert2中为用户提供反馈作为信息。处理SweetAlert2中的AJAX返回值

这是我SweetAlert2代码:

$('#sweet-ajax').click(function() {

swal({

title: "Sure?",

text: "Clicking on validated sends the data to our tool.",

type: "warning",

showCancelButton: true,

closeOnConfirm: false,

confirmButtonText: "Yes, submit!",

cancelButtonText: "Cancel",

showLoaderOnConfirm: true,

confirmButtonClass: 'btn btn-success',

cancelButtonClass: 'btn btn-danger m-l-10',

preConfirm: function(givenData){

return new Promise(function(resolve, reject) {

setTimeout(function(){

//if statment only for test purposes filled with 2==1

if(2 == 1){

swal("Oops", "Sorry something strange happend!", "error")

}else{

resolve()

}

}, 2000)

})

},

allowOutsideClick: false

}).then(function(givenData){

$.ajax({

type: "post",

url: "/assets/php/checkTool.php",

data: {registration: "success", amount: ammountInput, email: "[email protected]"},

})

swal({

//only if the response from the AJAX is correct - but how?

type: 'success',

title: 'Correct!',

html: 'All safe! Here is the answer from the tool: ' //need to get the return value of the AJAX request and append it here

})

}, function(dismiss) {

if (dismiss === 'cancel') {

swal(

'Cancelled',

'The action have been cancelled by the user :-)',

'error'

)

}

})

});

而且checkTool.php文件:

$registration = $_POST['registration'];

$ammountInput= $_POST['ammount'];

$email= $_POST['email'];

//only some demo things here. Implement it after the SweetAlert2 stuff works properly

if ($registration == "success"){

return response(json_encode(array("abc"=>'Success')));

}else{

return response(json_encode(array("abc"=>'Error')));

}

?>

我怎么能现在确定的是什么从SweetAlert2的JavaScript代码AJAX请求的响应?

是否可以处理SweetAlert2中的AJAX响应?

2017-07-29

Fabian

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值