My Ajax method looks like this
$.post(url,{
ajax_call:\"putDonation\",
addresse:addresse,
phone:phone,
email
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.